Skip to content
Snippets Groups Projects

Update trainer

2 files
+ 49
0
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -111,4 +111,41 @@ function updateDetailsTrainers(trainerId) {
</div>
</div>
`
}
function createTrainer() {
const name = document.getElementById('trainerName').value;
const profileUrl = document.getElementById('trainerProfileUrl').value;
const trainer = {
name: name,
profileUrl: profileUrl
};
fetch('/pokemon/api/trainers', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(trainer),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
// Refresh the trainers table
fetch('/pokemon/api/trainers')
.then(res => res.json())
.then(data => {
pokemonTrainers = data;
createPokemonTrainersTable();
})
.catch(err => {
console.error(`Unable to fetch Pokemon Trainers: ${err.status}`);
console.error(err);
});
})
.catch((error) => {
console.error('Error:', error);
});
}
\ No newline at end of file
Loading