Wikipedia app problem

Wikipedia app problem
0

#1

Hi, I seem to be having a problem using the wikipedia api, it was returning data but I changed the query and now I’m getting an error: status 404 response error. I’ve put the the following query into my browser and I get a successful response:

https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=peter&srlimit=10&format=json

but my code returns failure, any suggestions where I am going wrong?

code:

    getWikiArts() {

      $.ajax({
		    url: 'http://en.wikipedia.org/w/api.php',
		    jsonp: 'jsonp',
		    dataType: 'jsonp',
		    data: {
			    action: 'query',
          list: 'search', 
          srsearch: 'peter', 
          srlimit: '10',
			    format: 'json'
		    },
  		  success: function(arts) {
          console.log(" heelo", arts.query.search[0].title)
        },
        error: function (jqXHR, exception) {
          console.log('error: status ' + jqXHR.status + ' response ' + exception);
			  }
		  });
	  }

Thanks for any help…


#2

Remove jsonp and add origin: '*':

function getWikiArts() {
  $.ajax({
    url: 'https://en.wikipedia.org/w/api.php',
    data: {
      action: 'query',
      list: 'search',
      srsearch: 'peter',
      srlimit: '10',
      format: 'json',
      origin: '*',  //  <-- add this
    },

    success: function(arts) {
      console.log(' heelo', arts.query.search[0].title);
    },
    error: function(jqXHR, exception) {
      console.log('error: status ' + jqXHR.status + ' response ' + exception);
    },
  });
}

#3

Fantastic, thank you, is that a CORS problem?


#4

404 was jsonp problem. After removing jsonp you’ll get CORS which is solved by origin: '*'.