API Wikipedia Viewer : Failed to load for <script> element

API Wikipedia Viewer : Failed to load for <script> element


I’m fighting ( :slight_smile: ) with Wikipidia Viewer and I really don’t understand why my request doesn’t work, i’m really confused :


  $('form').submit(function() {
    var keyWord = $("#input-search").val();

    $.ajax( {
      method: 'GET',
      url: "https://en.wikipedia.org/w/api.php",
      dataType : 'jsonp',
      headers : { 'Api-User-Agent': 'Example/1.0' },
      data: {
        action: "opensearch",
        format: "json",
        origin: "*",
        search: keyWord,
        formatversion: "2"
      success: function(data) {
      error: function(response) {

I have this message in console :

You can check my project here : Api Viewer codepen

Thank you for your help,



The form is submitting data to some index.html. You don’t really want to load a new page when you submit the form (since you want the data to display on the same page). You can add an event parameter in the submit event handler, then call event.preventDefault() to prevent that behavior.

$('form').submit(function(event) {
  // ... rest of the code ...

You’ll then hit another error. Your code is getting the value of some input with the input-search id, but there’s no such input element in your form.


About “input-search” I forgot to copy my changes in local to codepen HTML section. Sorry about that.

Thank you for your help !!

I didn’t know “event.preventDefault();” I will loonking for more informations about it. Now I have a success return !

Thanks a lot !