getJSON和无效标签 [英] getJSON and invalid label
问题描述
我正在尝试从URL获取json数据.网址在FF中正常运行.我正在尝试这样的代码
$.getJSON("http://testsite.com/1234/?callback=?", function(data){
//here i am getting invalid label error**
}
);
当我尝试不使用callback =时?我正在获取空数据
$.getJSON("http://testsite.com/1234/", function(data){
//here i am data = ""
}
);
出了什么问题?
您似乎从中获取的网站不支持JSONP,并且使用以下URL:
http://testsite.com/1234/?callback=?
正在尝试使用 JSONP ,但是服务器返回简单的JSON响应(未包装在函数中).
使用此URL:
http://testsite.com/1234/
它根本没有尝试JSONP,并且被同源政策所阻止. /p>
要从远程域中获取数据,它需要支持JSONP,以便可以通过GET请求进行抓取,因此您需要为该域添加支持,或者通过自己的请求代理该请求.
I am trying to get json data from a url. Url is working ok in FF. I am trying code like this
$.getJSON("http://testsite.com/1234/?callback=?", function(data){
//here i am getting invalid label error**
}
);
When i am trying without callback=? i am getting empty data
$.getJSON("http://testsite.com/1234/", function(data){
//here i am data = ""
}
);
Whats going wrong?
It looks like the site you're fetching from doesn't support JSONP, with this URL:
http://testsite.com/1234/?callback=?
It's trying to use JSONP, but the server is returning a plain JSON response (not wrapped in a function).
With this URL:
http://testsite.com/1234/
It's not trying JSONP at all, and being blocked by the same-origin policy.
To fetch data from a remote domain, it needs to support JSONP so it can be grabbed with a GET request, so you'll need to either add support to that domain, or proxy the request through your own.
这篇关于getJSON和无效标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!