Unable to fetch data from mediawiki api using XMLHttpRequest

Tell us what’s happening:

request always gets cancelled

Your code so far

submit.onclick = function(){
   var xhr = new XMLHttpRequest();
  xhr.open('GET','https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=apple',true);
  xhr.setRequestHeader( 'Api-User-Agent', 'sushanthrao6@gmail.com' );
  xhr.onreadystatechange = function(){
    if(xhr.readyState == 4 &&  xhr.status == 200){
       var response = JSON.parse(xhr.responseText);
        alert(response);
    }
  };
  xhr.send();
};

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/build-a-wikipedia-viewer

Add origin=* to the request as shown here

still the request is getting canceled after adding origin = * in the url
xhr status is cancelled

Thanks SkyC it worked