简体   繁体   中英

MediaWiki API and Access-Control-Allow-Origin

Im trying to make an app in angular.js which will allow to perform search in mediawiki based on provided word. I have used yeoman to scafold my app, and im running it on local server with 'grunt serve'. However no matter what i try, im getting error regarding crossorigin requests, in chrome for an example:

XMLHttpRequest cannot load http://en.wikipedia.org/w/api.php . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.

I have tried to set 'origin' header of my requests to localhost adress but it did'nt helped in firefox, and chrome refused to even set this header throwing message in the console that this is unsafe.

This is a CORS issue.

In this instance that means that you need to manage the hosted wiki on which API.php is being called.

Your error states you are trying to call Wikipedia and not your own MediaWiki instance.

Edit the URL of the API in your code, or better still share the code here so folks can see your real problem.

If you are going to use different hosts and domains then you will need to enable CORS on the host MediaWiki where the api.php resided.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM