Wikipedia Viewer getJSON correct?

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

function searchWiki() {
$.getJSON(“*”, function(a) {
var pageList = [];
pageList = Object.keys(a.query.pages);

for(var i = 0; i < pageList.length; i++) {
  var pageNum = pageList[i];
  var result =[pageNum].title;


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 =[pageNum].title;

should be

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

1 Like

My code still doesn’t work: :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