No response from MediaWiki API using jQuery

后端 未结 4 995
忘掉有多难
忘掉有多难 2020-11-30 04:12

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&         


        
4条回答
  •  迷失自我
    2020-11-30 05:00

    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.

    Without using JSONP you're hitting the same-origin policy which is blocking the XmlHttpRequest from getting any data back.

提交回复
热议问题