I am trying to build the random quote machine, and built my own object of quotes to use stored here.
I looked at a simple JSON§ tutorial which used the following code:
And that works fine. I get the object in the console.
But if I change the link to my object, the console is blank. Code that results in a blank console:
Can anyone tell me what is going wrong?
It’s because your JSON file has an invalid format. Use this tool to verify your JSON file :).
To add to my previous answer:
You should always add the error handler to your AJAX calls, even if it’s just to log the error:
// The request succeeded and the data is valid JSON
// Something wrong happened.
console.error('We could not fetch or parse the data:', error);
Be aware that this is not guaranteed to solve the problem. For instance, in your specific scenario, your JSON file had a bad format, but the error received on the
fail function didn’t say anything about the data being malformed. You’ll just have to test the data in those cases .
Anyway, I hope it helps !
Thank you for the reply!
Edit: Just checked copying the data and found the extra comma.
Edit 2: Waited for Git raw to update, and still found a blank console: Codepen.
Edit 3: Removed the .json just in case that was the issue, it wasn’t. Raw data now here: https://raw.githubusercontent.com/themagicbean/bojackquotejson/master/bojackquotes
The current problem is that your JSONP definition is wrong, you should use the function name to be called instead of a
On the other hand, JSONP is insecure, so you shouldn’t be using it anyway .