webkit based browser interpretate the json as a script

被刻印的时光 ゝ 提交于 2019-12-24 03:16:20

问题


im just tryin to get my zootool items via js to push them in my blog's footer...but with no success. here's the code im using (jquery framework)

jQuery(document).ready(function($)
{

//first try
var url = "http://zootool.com/api/users/items/?username=USER_NAME&apikey=API_KEY&jsonpcallback=?"
$.getJSON(url, function(data){ console.log(data); });

//second try
url2 = "http://zootool.com/api/users/items/?";
data = "username=USER_NAME&apikey=API_KEY";

$.ajax(
{
 url: url2, dataType: 'jsonp', data: data,
 success: function(data){ console.log(data); }
});

}

webkit based browser tells me that: "Resource interpreted as script but transferred with MIME type application/json."

firefox works good, i get an application/json; utf-8 object that i can parse succesfully. do you know what could be the problem? thanks a lot in advance!

Luca


回答1:


A JSONP response is not really JSON but JavaScript, so the Content-Type in the response header should be application/javascript.




回答2:


directly from the creator of zootool:


the api hasn't supported callbacks for jsonp so far. I just added them so your first version should work with a little adjustment. you have to rename jsonpcallback to callback to make it work. take a look here:

http://pastebin.com/vA9wcySa



来源:https://stackoverflow.com/questions/3364366/webkit-based-browser-interpretate-the-json-as-a-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!