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
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.
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.
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).
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).
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.