What's wrong with my wikipedia viewer

I don’t know what to do. It says [object object] when I try to get it to work what should I do. Do I need to change
what var title equals.

Hello,

You need to stringify the return object in order to view it correctly.

document.write(JSON.stringify(result.query.pages));

This will show the data returned in the way you want.However the data that your API returns seems complicated.

Try to use below API which returns data in a simple structure.

"https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=" + search term goes here + "&callback=?"

Use your browsers console to check weather each step of your code is working.


This will make your life easier.

Regards,
Sachithra.

If you are wanting to use this particular Wikipedia endpoint, then you could use something like below for the success function to display the results from the result response…

      success: function(result) {
        for (var html = "", i = 0; i < result[1].length; i++) {
          var title = result[1][i];
          var href = result[3][i];
          var description = result[2][i];
          html += `<h2><a href="${title}">${title}</a></h2>
                   <p>${description}</p>`;
        }
        $('#test').html(html);
      }