跨域jquery ajax请求 [英] cross domain jquery ajax request
问题描述
我正在向 url http://json-cricket.appspot.com 发送 ajax 请求/score.json通过代码
I am sending ajax request to a url http://json-cricket.appspot.com/score.json by the code
var url="http://json-cricket.appspot.com/score.json";
$.get(url, function (data) {
console.log(data);
}, 'json');
这不起作用,但如果我将 '?callback=?
' 添加到 url,那么它将起作用.即
and this is not working, but if I add '?callback=?
' to the url, then it will work. i.e.
var url="http://json-cricket.appspot.com/score.json?callback=?";
$.get(url, function (data) {
console.log(data);
}, 'json');
然后就可以了.
两个 url 都会给出输出.唯一的区别是后者将结果包装在 ?(result)
上.
Both url will give the output. Only the difference is the the latter one will wrap the results on ?(result)
.
据我所知,谁能解释一下发生了什么?它取自此处.
For my knowledge, can anyone explain me what is happening? It was taken from here.
任何进一步研究的链接都将非常值得赞赏.
Any link for further study would be highly appreciable.
推荐答案
因为是跨域ajax请求.
It is because it is a cross-domain ajax request.
有关更多信息,您可以查看维基百科文章http://en.wikipedia.org/wiki/JSON#JSONP
For more info, you can have a look at the wikipedia article http://en.wikipedia.org/wiki/JSON#JSONP
这篇关于跨域jquery ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!