Can t get json data in Wikipedia Viewer

Hello,

I m trying to access some json data, to log it but it doesn t work no matter what, I tried several URL’s even from wikipedia’s examples and no result, nothing happens. I tested my code on submit, it gets the query but when it tries to grab json data it gets stuck there. This is my code so far:

$(document).ready(function(){
   $("#form").submit(function(){   
    var query = $("#query").val();
  
    var url = 'https://en.wikipedia.org/w/api.php?action=opensearch&search=' + query+ '&format=json&callback=?';
     
    $.getJSON(url, function(json){
      console.log(json);
    });
 });  
});
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div class="articles">
     <div class="random">
   <a href="https://en.wikipedia.org/wiki/Special:Random" target="_blank">Click here for a random article</a>
  </div>
  <form id="form" >
    <input type="search" id="query">
     <div class="close"></div>
    </form>
    
    <p>click icon to search</p>
  </div>

</body>
</html>

Can you share the html too?

This is the html for now i edited the post

Thanks. One quick idea: do you have jquery in your project?

yeah i m using this https://code.jquery.com/jquery-3.3.1.min.js and also this from bootstrap https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js.
I can console the value from my input so the issue is with json. I think it has to do with cross origin issue

I added e.preventDefault(); after submit and now it works. Apparently this was the cause

I added the action attribute to your input form, and now I can see the response for my query, but it looks like it’s coming back in JS, not XHR.

.

My guess is that you need to add the response data type in your api call. I’ll play with it for a bit longer and let you know if I find anything.

Oh, great! You got it!

thank you for your help

Don’t know if I actually helped! But happy to try!

Damn their API is horrible… so messed up