Can someone check my 'Build a Wikipedia Viewer' code?

Can’t figure out why my code wont perform correctly.

$(document).ready(function() {

  // Submit

  $("#wikiForm").submit(function(event) {

    //Search Submission
    var submission = document.getElementById("getInput").value;

    //Attach to Wiki API

    var wikiApi = 'https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&limit=10&srsearch=' + submission +"&callback=?";

    $.getJSON("wikiApi", function(data) {
    
    var html = "";
      
    $.each(data.query.pages, function(val) {
      var keys = Object.keys(val);
      html += "<div class = 'list'>";
      $.each(function(key) {
html += "<strong>" + key + "</strong>: " + val[key] + "<br>";
      }); //End of data function
      html += "</div><br>";
    }); //End of keys function
      
      $(".results").html(html);
      
  }); // End getJSON

    event.preventDefault();

  }); // End Submit
 
}); // End document

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

1 Like

This might be the culprit:

$.getJSON("wikiApi", function(data) {

should be

// no quote marks around `wikiApi`
$.getJSON(wikiApi, function(data) {
1 Like

Thanks! Greatly appreciated! Now, I’m accessing the API but I’m not displaying the info and I can’t figure out why. Can you help me out? http://codepen.io/DRick504/pen/WoLdeW

@DRick504 Have you been working with your browsers console and not just the codepen one? There’s some very valuable information in there that should give you a good place to work from in figuring out your issue. At the very least it’ll give you some good google search material!

One thing I’ve learned is… 99% of the time, the answer’s in the console. You might have to know what to log in order to find it, but its usually there.

I was totally handicapped by codepens console for the longest time because I thought there wasn’t a huge difference between the two… there is. The console is your friend :slight_smile:

1 Like

Thanks for the heads up! No, I havent but I will start now