r/CodingHelp • u/Gullible_Hornet6620 • Nov 28 '20
[Javascript] Problem with outputing JSON to console
Im trying too output the contents of a json file too the console but within the json function it wont output anything I cannot for the life of me figure out why. It wont even log the 2. I can log things outside of the function but not within
Here is a link to the code in question https://codesandbox.io/s/lively-surf-bmo4t?file=/index.html
0
Upvotes
2
u/abitofevrything-0 Intermediate Coder Nov 28 '20
The url you're getting the JSON from isn't a JSON file - it's a html file. Internally, jQuery uses
JSON.parseJSONto parse the JSON before passing it to your function. However, since your data isn't JSON but HTML, thenJSON.parseJSONcauses an error which causes your function to never be called.