Problem with Wikipedia viewer/API

Hi there!

I’m having an issue with the Wikipedia Viewer challenge, namely getting hold of the JSON for the search results.

I’ve tried using the $.ajax and $.getJSON functions, and neither is working for me.


//Submit button action
$("#submit-btn").on(“click”, function() {
var input = $("#text-search").val();
var searchURL = ""+input+"&gsrlimit=10&callback=?";

//Ajax attempt
type: “GET”,
url: searchURL,
dataType: “json”,
success: function (data) {
error: function(errorMsg) {

//getJson attempt
$.getJSON(searchURL, function (data) {


The URL I generate works when I test it in my browser, but in Codepen the following is returned in the console:

Object {
continue: Object {
excontinue: 1
query: Object {
pages: Object {}

Does anyone know why I’m not getting the proper response in codepen? I thought I’d worked around the json/jsonp problem, but clearly there’s still some issue.

I used this form in my wikipedia viewer

      url: "",
      dataType: "json",
      data: {
        action: "opensearch",
        format: "json",
        origin: "*",
        search: searchTerm,
        formatversion: "2"

Maybe you can tweak it a bit, since you’re using query instead of opensearch. But I don’t know how it will turn out in codepen, since mine is using gh pages.

Can you please link to your CodePen? That will make it easier to provide feedback.

@PortableStick Sure! Here:

@kevcomedia I did try opensearch and it worked (thanks!), though I’d like to know what’s wrong with the generator version as well.

I can’t help you with that :slight_frown:. I couldn’t manage to make action=query to work. However, once you are done with the wikipedia viewer (or just plain stuck) try taking a look at how other campers did theirs (or at least, what request URL they used).

I’ll give that a go for sure - the Wikipedia API is pretty tricky!

In the meantime I’ve set up a version that uses opensearch. Still need to figure out the finer points of using css, but the information seems to be displayed properly: