How to get data from mediawiki api using Angularjs?

888 views Asked by At

While I try to access wiki api using Angularjs $http.get(), CORS issues occured. Here is my code

$http.get('http://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&exintro=&titles=India') .success(function(data){ console.log('data' +data); });

And this is the error message

XMLHttpRequest cannot load https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&exintro=&titles=India. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

3

There are 3 answers

0
MaxSem On BEST ANSWER

Use JSONP for cross-site requests.

0
Blaise On

Check the following SO answer regarding CORS:

CORS, Cordova, AngularJs $http and file:// confusion

As well as the mentioned in the comment:

http://www.html5rocks.com/en/tutorials/cors/

0
Tgr On

See Manual:CORS and API:Cross-site requests. Specifically, you need to set $wgCrossSiteAJAXdomains and add an origin parameter to your request.