How to retrieve data from Wikipedia API using JSON?

和自甴很熟 提交于 2019-11-28 11:32:55

Use the following code to get the data:

$.getJSON(playListURL ,function(data) {
        $.each(data.query.pages, function(i, item) {
            alert(item.title);

        });
    });

Demo is at http://jsfiddle.net/dyeqy/3/

var playListURL = 'http://en.wikipedia.org/w/api.php?format=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?';

$.getJSON(playListURL ,function(data) {
    var hash = data
    var page_value = ""
    $.each(data["query"]["pages"],function(k,v){
        alert(k)
        $.each(v,function(key,val){
          alert(key)
        });
    });
});

Like this you can take the revisions values also.

It should be data.query.pages instead of data.pages

Working Fiddle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!