Help retrieving Wikipedia API results

It’s nearly 4am, and I cannot for the life of me get my ajax function to successfully get data from Wikipedia’s API.

$.ajax({
   url: 'https://en.wikipedia.org/w/api.php',
   type: 'GET',
   datatype: 'jsonp',
   data: {
     action: 'opensearch',
     format: 'json',
     search: searchTerm,
     limit: '10',
     callback: '?'
   },
   xhrFields: {
     withCredentials: false
   },
   success: function(json) {
     $('#results').html(searchTerm + ' IT WORKED???');
   },
   error: function(a, b, c) {
     $('#results').html('Search unsuccessful: ' + a + ', ' + b + ', ' + c);
   }
});

If anyone can give me a hint as to what I’m doing wrong, I’d really appreciate it!

And here’s a link to the codepen if you wanna fiddle around with it.

High five for the dedication to coding until 4am! Your project looks great and that’s some really clean code. The only problem with burning the midnight oil is that we make the small mistakes more. datatype should be dataType. Easy fix! :thumbsup:

1 Like

Oh man, thank you so much for catching that!! :star::star:

1 Like