How to get data from mediawiki api using Angularjs?

僤鯓⒐⒋嵵緔 提交于 2019-12-08 08:16:28

问题


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.


回答1:


Use JSONP for cross-site requests.




回答2:


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/




回答3:


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



来源:https://stackoverflow.com/questions/30935277/how-to-get-data-from-mediawiki-api-using-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!