I'm trying to grab a songkick json feed using the below:
var jsonpArgs = {
url: obj.url,
load: function(data) {
console.log(dojo.fromJson(data));
},
error: function(error) {
new ErrorDialog({ title: 'Error', content: error });
}
};
dojo.io.script.get(jsonpArgs);
It loads the data fine, but it returns:
Resource interpreted as script but transferred with MIME type application/json. Uncaught SyntaxError: Unexpected token :
This unexpected token coming from the contents of the file (line 1):
{ "r开发者_开发技巧esultsPage":
I'm guessing it's because the content coming back isn't be interpreted as json properly but I don't know what I'm doing wrong. I have tried specifying the callback parameter but it does nothing (not jsonp?).
Any ideas?
It looks like the feed does not support JSONP responses. Looking at their modest documentation I don't see how to specify a callback (the crucial part of JSONP). So obviously you are getting an error — JSONP uses <script>
to retrieve the data, yet the data is of wrong type.
Another thing is you have to specify jsonp
parameter, which is callback parameter. But it looks like a moot point, because I don't see your feed service supporting it.
So you best bet is to do a server-side call to this service using a proxy or something similar. This way you avoid cross-platform problems and can deal with JSON or XML directly.
精彩评论