没有来自MediaWiki API的使用jQuery的响应 [英] No response from MediaWiki API using jQuery
本文介绍了没有来自MediaWiki API的使用jQuery的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从维基百科中获取一些JSON的内容:
I've tried to get some content from Wikipedia as JSON:
$.getJSON("http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&titles="+title+"&format=json", function(data) {
doSomethingWith(data);
});
但我没有回应。如果我粘贴到浏览器的地址栏,例如
But I got nothing in response. If I paste to the browser's adress bar, something like
http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&titles=jQuery&format=json
得到预期的内容。有什么问题?
I get the expected content. What's wrong?
推荐答案
您需要使用& callback =?上添加 $。getJSON()
querystring,像这样:
You need to trigger JSONP behavior with $.getJSON()
by adding &callback=?
on the querystring, like this:
$.getJSON("http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&titles="+title+"&format=json&callback=?", function(data) {
doSomethingWith(data);
});
You can test it here.
如果不使用JSONP,您将遇到同源策略阻止XmlHttpRequest获取任何数据。
Without using JSONP you're hitting the same-origin policy which is blocking the XmlHttpRequest from getting any data back.
这篇关于没有来自MediaWiki API的使用jQuery的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文