最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to retrieve data from Wikipedia API using JSON? - Stack Overflow

programmeradmin0浏览0评论

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

var playListURL = '.php?format=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?';

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

DEMO LINK :- /

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=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?';

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

DEMO LINK :- http://jsfiddle.net/rushijogle/dyeqy/

Share Improve this question edited Sep 19, 2014 at 17:30 MrLore 3,7802 gold badges29 silver badges37 bronze badges asked May 24, 2013 at 12:52 Rushikesh jogleRushikesh jogle 5912 gold badges9 silver badges29 bronze badges 1
  • check my answer you will get the proper result by that. – user2334807 Commented May 24, 2013 at 13:12
Add a comment  | 

3 Answers 3

Reset to default 6

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

发布评论

评论列表(0)

  1. 暂无评论