Answered by:
Update function not working

Question
-
User1421620300 posted
I need help with fixing the update function of my application. After addition of the putHero() function there has been several errors. My testing is going fine but i am just beginning to touch jquery in all of the caveats involved. the error occurs when i click on the update button the app deletes the information for the current row when it should be updating the data. I have been trying to step through my code but i am just novice in JQuery at the moment so part of my consistency in this area is hindered.." Any suggestions appreciated! Thank, Markus.
Screenshots: https://imgur.com/a/1xnm3ol
GITHUB: https://github.com/Andrew112/SuperHeroDB
function putHero() {
updateHero.FirstName = $("#UpdateFirstname").val();
updateHero.LastName = $("#UpdateLastname").val();
updateHero.HeroName = $("#UpdateHeroname").val();
updateHero.PlaceOfBirth = $("#UpdatePlaceOfBirth").val();
updateHero.Combat = $("#UpdateCombatPoints").val();
$.ajax({
url: "Service/SuperHeroService.svc/UpdateHero/" + updateHero.Id,
type: "PUT",
datatype: "json",
contentType: "application/json",
data: JSON.stringify(updateHero),
success: function () {
showOverview();
//heroId = result;
//editHero(heroId);
//showAdd();
// console.log(heroId);}
});
}Wednesday, March 25, 2020 5:51 PM
Answers
-
User415553908 posted
To fix your specific problem, ensure your putHero method follows correct casing to match input element ids:
function putHero() { // notice lower case first latter in all ids below: updateHero.Firstname = $("#updateFirstname").val(); updateHero.LastName = $("#updateLastname").val(); updateHero.HeroName = $("#updateHeroname").val(); updateHero.PlaceOfBirth = $("#updatePlaceOfBirth").val(); updateHero.Combat = $("#updateCombatPoints").val();
there's another issue that you might already be aware of (it's not part of your question but i'd just point it out anyway):
when you call your putHero, your updateHero.id is always null as far as I can tell:
$.ajax({ url: "Service/SuperHeroService.svc/UpdateHero/" + updateHero.Id, // this is null
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 26, 2020 1:24 AM -
User-474980206 posted
you never define updateHero, so you should be getting debug errors.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 26, 2020 6:02 PM
All replies
-
User415553908 posted
To fix your specific problem, ensure your putHero method follows correct casing to match input element ids:
function putHero() { // notice lower case first latter in all ids below: updateHero.Firstname = $("#updateFirstname").val(); updateHero.LastName = $("#updateLastname").val(); updateHero.HeroName = $("#updateHeroname").val(); updateHero.PlaceOfBirth = $("#updatePlaceOfBirth").val(); updateHero.Combat = $("#updateCombatPoints").val();
there's another issue that you might already be aware of (it's not part of your question but i'd just point it out anyway):
when you call your putHero, your updateHero.id is always null as far as I can tell:
$.ajax({ url: "Service/SuperHeroService.svc/UpdateHero/" + updateHero.Id, // this is null
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 26, 2020 1:24 AM -
User-474980206 posted
you never define updateHero, so you should be getting debug errors.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 26, 2020 6:02 PM