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
No related branches found
No related tags found
2 merge requests!102Update trainer,!67Issue #2
This commit is part of merge request !102. Comments created here will be created in the context of that merge request.
...@@ -111,4 +111,41 @@ function updateDetailsTrainers(trainerId) { ...@@ -111,4 +111,41 @@ function updateDetailsTrainers(trainerId) {
</div> </div>
</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 @@ ...@@ -40,5 +40,17 @@
</div> </div>
</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> </body>
</html> </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