Wikipedia Viewer getJSON correct?

I am trying to get the json data from Wikipedia API. Is this below function correct?

function searchWiki() {
$.getJSON(“https://en.wikipedia.org/w/api.php?action=query&format=json&generator=allpages&gapfrom=gandhi&gaplimit=10&origin=*”, function(a) {
var pageList = [];
pageList = Object.keys(a.query.pages);

for(var i = 0; i < pageList.length; i++) {
  var pageNum = pageList[i];
  var result = a.query.page[pageNum].title;
  $('#wiki').append(result+"<br>");
}  
//https://en.wikipedia.org/?curid=1326830

});
}

I am trying to make a code just to test if I am getting data from wikipedia API correctly, that why I put ‘gapfrom=gandhi’.

What is wrong with this code above?

var result = a.query.page[pageNum].title;

should be

var result = a.query.pages[pageNum].title;

1 Like

My code still doesn’t work: http://codepen.io/raulfm/pen/QpoMNa?editors=1010 :disappointed:

your codepen didnt work because its missing jQuery library you are trying to use… once i add jQuery i was able to see your list :slight_smile:

1 Like

Thanks! It worked now! =D

sure thing glad to help