Wikipedia Viewer - ajax call difficulty

Wikipedia Viewer - ajax call difficulty
0

#1

I am trying to get the json data from wikipedia. But, when I make my ajax call, nothing seems to be happening - no success data is logged nor is any error data logged. Here is the javascript code that I am using:

$(document).ready(function() {  
  $("#query").on("submit", function() {
    var root = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&generator=search&redirects=1&exsentences=1&exlimit=10&exintro=1&explaintext=1&gsrnamespace=*&gsrlimit=10&gsrsearch=";
    var q = encodeURI($("#q").val());
    var cb = "&callback=?";
    var url = root + q + cb;
    $.ajax({
      url: url,
      type: "GET",
      dataType: "json",
      success: function(data) {
        console.log(data);
      },
      error: function(error) {
        console.log(error);
      }
    });
  });
});

What should I be doing differently?


#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#3

Thank you! I will make sure to do this next time.