Skip to content
Snippets Groups Projects
Commit 6a3ddb4e authored by Gyunderov, I.A. (Ivan, Student B-TCS)'s avatar Gyunderov, I.A. (Ivan, Student B-TCS)
Browse files

Issue #2 solved

parent 30999777
Branches createTrainer
No related tags found
No related merge requests found
......@@ -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
......@@ -40,5 +40,17 @@
</div>
</div>
<form id="createTrainerForm" onsubmit="event.preventDefault(); createTrainer();">
<div class="form-group col-md-6">
<label for="trainerName">Name</label>
<input type="text" class="form-control" id="trainerName" required>
</div>
<div class="form-group col-md-6">
<label for="trainerProfileUrl">Profile URL (optional)</label>
<input type="text" class="form-control" id="trainerProfileUrl">
</div>
<button type="submit" class="btn btn-primary">Create Trainer</button>
</form>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment