Could their be a possible fix for this error that i receive when trying to compile my new script. I have modified the app to update an existing object form the DB. But for some reason the run time compilation throws an error! It causes the page to react
with duplicate data from other tables to show in corresponding row or data-set." Markus.
Have you tried placing a `debugger;` just prior to the line with the mentioned error (app.js:38) to see what the value of your `heroId` property is? It sounds like it's undefined, so you'll likely want to take a look at the available stack trace and responses
from your endpoints using the Developer Tools (F12) within your browser.
If you have a specific event that is triggering the error, consider placing debuggers throughout your code to isolate where the error is coming from. The Developer Tools in your browser are going to be your best friend in this case.
I tried your code from the github and I could not reproduce your problem since you embedded the number "1,2,3" to pass the parameter "heroId".
Hence, the "edit undefined" error could not occur from my side.
However, there are two errors in the function "putHero" in service.js file that may fails you.
1.You should assign the updated value to the corresponding field for updateHero variable. However, you just simply assign them to updateHero variable
2.You are wrongly using the selector for the update input field because you named the input field with name without the capital letter "U". Instead, you should select the html element by "#updateFirstname" for
instance.
What's more, you constructed the data model "SuperHero" with the property "Id" but what I can see is that you are access "id" for a "hero" instance in the code.
You have to polish the code especially for spelling error there.
Hope this can help you.
Best regards,
Sean
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
251 Points
423 Posts
Update function throwing error!
Mar 19, 2020 02:53 AM|Markus33|LINK
Could their be a possible fix for this error that i receive when trying to compile my new script. I have modified the app to update an existing object form the DB. But for some reason the run time compilation throws an error! It causes the page to react with duplicate data from other tables to show in corresponding row or data-set." Markus.
https://github.com/Andrew112/SuperHeroDB.git
Inspector: edit undefined app.js 38
function editHero(heroId) {
showUpdate();
Line: 38: console.info("Edit " + heroId);
for (var i = 0; i < heroes.length; i++)
{
All-Star
114593 Points
18503 Posts
MVP
Re: Update function throwing error!
Mar 19, 2020 03:21 AM|Rion Williams|LINK
Have you tried placing a `debugger;` just prior to the line with the mentioned error (app.js:38) to see what the value of your `heroId` property is? It sounds like it's undefined, so you'll likely want to take a look at the available stack trace and responses from your endpoints using the Developer Tools (F12) within your browser.
If you have a specific event that is triggering the error, consider placing debuggers throughout your code to isolate where the error is coming from. The Developer Tools in your browser are going to be your best friend in this case.
Contributor
2850 Points
840 Posts
Re: Update function throwing error!
Mar 19, 2020 07:24 AM|Sean Fang|LINK
Hi, Markus33,
I tried your code from the github and I could not reproduce your problem since you embedded the number "1,2,3" to pass the parameter "heroId".
Hence, the "edit undefined" error could not occur from my side.
However, there are two errors in the function "putHero" in service.js file that may fails you.
1.You should assign the updated value to the corresponding field for updateHero variable. However, you just simply assign them to updateHero variable
2.You are wrongly using the selector for the update input field because you named the input field with name without the capital letter "U". Instead, you should select the html element by "#updateFirstname" for instance.
After Update code:
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(); } }); }
Demo:
What's more, you constructed the data model "SuperHero" with the property "Id" but what I can see is that you are access "id" for a "hero" instance in the code.
You have to polish the code especially for spelling error there.
Hope this can help you.
Best regards,
Sean