Wiki Viewer App won't display getJSON data

Wiki Viewer App won't display getJSON data
0.0 0

#1

So I can’t seem to figure out how the getJSON data that the function retrieves.
the console,logs the json data in a multidimensional array,but I can’t seem to access it using the usual methods.

the append method doesn’t seem to do a lot.


#2

on line 9 in your js code -

console.log(data);

open the codepen console, what’s in there?


#3

It gives a array like

[“something”[“something”,“something”,“something”,“something”]]


#4

can you copy and paste url for the codepen


#5

this is the link to the codepen…I hope you can make some sense of it.


#6

When you submit a form, the page refreshes. So, what’s happening is your code is right, but the page refreshes before you can see the result. In order to prevent the page from refreshing, you need to include event.preventDefault() in your submit handler. Like so:

$(document).ready(function() {
  $("#formData").submit(function(event) {
    var searchTerm = $("#Search").val();
    var url = "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + searchTerm + "&limit=5&format=json&callback=?";
    event.preventDefault(); //  this is what was missing :)
    $.getJSON(url, function(data) {
      console.log(data);
      $('#firstpara').append("<p>"+data+"</p>");

    });
  });
});

#7

Yes thank you very much,this seems to work now.I will now try to finish the rest of it.
Thanks again.