我已经知道了这个有很多,我只是不明白。它无关,与我的code,它必须做的饲料或东西,因为如果我换也可以用微博给它返回一个Object对象,它是完美的。
$.getJSON('http://rockbottom.nozzlmedia.com:8000/api/portland/?count=1&callback=?',function(json){ 执行console.log(JSON) });和我得到一个无效的标签错误。任何想法?
此外,一个侧面说明,我已经试过了AJAX方法,以及:
$。阿贾克斯({
网址:http://rockbottom.nozzlmedia.com:8000/api/portland/,
数据类型:JSONP,
数据:'计数= 1',
成功:函数(MSG){
执行console.log(味精)
}
});
和两者给予同样的确切的错误,都做工精细与Flickr和Twitter的例子,所以它一定有什么做的饲料,但我不能够访问饲料,但我会要求他们修复的东西,如果这是他们的问题。
解决方案请确保服务器端可以处理JSONP请求正常。请参见这里例如。
修改:看来,服务器不换行的回调函数名返回的JSON对象。服务器应返回:
回调({JSON这里})
而不是
{JSON这里}
I've read about this a lot and I just can't figure it out. It has nothing to do with MY code, it has to do with the feed or something because if I swap it with a Twitter feed it returns an Object object which is perfect.
$.getJSON('http://rockbottom.nozzlmedia.com:8000/api/portland/?count=1&callback=?',function(json){
console.log(json)
});
And i get an "invalid label" error. Any ideas?
Also, a side note, I've tried the AJAX method as well:
$.ajax({
url: 'http://rockbottom.nozzlmedia.com:8000/api/portland/',
dataType: 'jsonp',
data: 'count=1',
success: function(msg){
console.log(msg)
}
});
and both give the same exact error, and both work fine with Flickr and Twitter examples, so it must be something to do with the feed, but I dont have access to the feed, but I could ask them to fix something IF it's their issue.
解决方案Make sure that the server side can handle the JSONP request properly. See here for example.
Edit: It seems that the server doesn't wrap the returned JSON object with the callback function name. The server should return:
callback( { json here } )
and not
{ json here }