• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

change JavaScript project endpoint from array to object

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a working project with the endpoint of array
Now I'm required to change it to object .
But this change ruined my project. I get the following error in the console:

What I have tried:
I changed the method of adding objects to the end point to be instead of
and then I got the above mentioned error in the console

here is the code:


and here the code








 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so diagnosing the problem...

If we look at the line, 88, where the problem is reported, we see allData.temp. The error tells us that allData is undefined at this point. The most likely cause is the endpoint failing or not returning what is expected. It's not an error, because that would have triggered the catch.

So, we want to examine the endpoint. The "Network" tab in Dev Tools is our best friend here. It will show us the result of the endpoint call; its response, status, and so on. Take a gander and see what the endpoint is doing that may be unexpected.
 
Hany Taha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:OK, so diagnosing the problem...

If we look at the line, 88, where the problem is reported, we see allData.temp. The error tells us that allData is undefined at this point. The most likely cause is the endpoint failing or not returning what is expected. It's not an error, because that would have triggered the catch.

So, we want to examine the endpoint. The "Network" tab in Dev Tools is our best friend here. It will show us the result of the endpoint call; its response, status, and so on. Take a gander and see what the endpoint is doing that may be unexpected.



Thanks for replying, Bear.
By referring to network tab in devtools, I found that Response of allData is an object like this
I hope that helps.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done. Looks like it's ok. So, setting a breakpoint at line 88, what does allData contain?
 
Hany Taha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Well done. Looks like it's ok. So, setting a breakpoint at line 88, what does allData contain?



I get
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Huh, I would normally say that means the request is failing, but since you got a good response in Dev Tools...

Firstly, I would move the fetch inside the try so that any errors in the request would be caught.

Secondly, verify that you are looking at the right request in Dev Tools (you can clear the console before making the request to make sure you're not looking at stale data).
 
Hany Taha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Huh, I would normally say that means the request is failing, but since you got a good response in Dev Tools...

Firstly, I would move the fetch inside the try so that any errors in the request would be caught.

Secondly, verify that you are looking at the right request in Dev Tools (you can clear the console before making the request to make sure you're not looking at stale data).



I got this response:
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A 404 means that end point was not found. Check your URLL.
 
Hany Taha
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally, I found my stupid mistake.
I was working on wrong app.js file which was accidentally created by me.
now everything works fine as expected.
I'm so sorry for you guys, specially Bear Bibeault who did great effort trying to find the error in my code wasting a lot of his time for a stupid mistake made by me.
thanks and sorry again.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for `fessing up! But not wasted. Someone might have similar problems in the future and this could be helpful.
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic