• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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: 67752
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: 67752
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: 67752
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: 67752
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: 67752
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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic