I’m trying to use the jquery, getJSON method to get JSON data from a public API. I keep getting the following errors when the callback of my getJSON request executes.
Warning: Resource interpreted as Script but transferred with MIME type text/html
Error: Uncaught SyntaxError: Unexpected token :
I’ve inspected the header of the response and, sure enough, it is set to text\html. Since this is a public API that I can’t control, how can I easily request and parse this JSON data?
For reference, the link below is the link to the JSON data that I am trying to acquire.
JSON Request (http://bitcoincharts.com/t/weighted_prices.json)
If you can’t control the mime type, use
jQuery.ajaxinstead ofjQuery.getJSON. Then in the success callback you can do something like this:Another thing you could try is:
Although I’m not sure if jQuery will complain if the mime type doesn’t match. It’s worth a shot though.
EDIT: On another note, how are you able to access that data from your script? Even though it’s a public API, it’s on another server and so that will violate the same-origin policy. When I do the following:
From my Chrome console, I see the following error:
You have to see if BitCoin Charts supports a JSONP alternative. Otherwise, your only option is to set up something on the server-side that grabs this data for you and returns it back to you in JSON with the correct mime-type.