I'm currently working on a userscript/extension for Chrome and am trying to pull in some JSON data from "some website". This was my approach:
$.get( "http://cloud.hartwig-at.de/~oliver/superuser.json",
function( data ) { console.log( data ); }
);
Of course, that leads to the following error:
XMLHttpRequest cannot load http://cloud.hartwig-at.de/~oliver/superuser.json. Origin http://superuser.com is not allowed by Access-Control-Allow-Origin.
I was able to resolve that after reading Origin 'url' is not allowed by Access-Control-Allow-Origin (among other questions). So, this is the next version:
$.get( "http://cloud.hartwig-at.de/~oliver/superuser.json",
function( data ) { console.log( data ); },
"jsonp"
);
Sadly, that results in another error:
Uncaught SyntaxError: Unexpected token : (superuser.json:2)
There's also a warning telling me "Resource interpreted as Script but transferred with MIME type text/plain:" which already gave me an idea what the trouble could be. (And more details were provided through Chrome says "Resource interpreted as script but transferred with MIME type text/plain.", what gives?)
Apparently, the HTTP server has to send the proper MIME type for my file, which would be application/json
.
Okay, So I quickly added the required change to my mime.types
and went for another go. But, no dice! The warning went away, the error didn't. I still get Uncaught SyntaxError: Unexpected token :
. (I had also previously attempted to utilize the mimeType
parameter to fix this, the outcome was the same.)
The MIME type looks fine though:
Now I'm somewhat out of ideas. The content of the .json
file validates fine on http://www.jslint.com/