How to retrieve data from Wikipedia API using JSON?

后端 未结 3 417
长情又很酷
长情又很酷 2020-12-10 18:00

Here I am fetching the data from Wikipedia using following code. but it is not working for me.

var playListURL = \'http://en.wikipedia.org/w/api.php?format=j         


        
相关标签:
3条回答
  • 2020-12-10 18:36

    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.

    0 讨论(0)
  • 2020-12-10 18:38

    Use the following code to get the data:

    $.getJSON(playListURL ,function(data) {
            $.each(data.query.pages, function(i, item) {
                alert(item.title);
    
            });
        });
    
    0 讨论(0)
  • 2020-12-10 18:45

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

    Working Fiddle

    0 讨论(0)
提交回复
热议问题