Wikipedia API + Cross-origin requests

前端 未结 5 878
自闭症患者
自闭症患者 2020-12-01 05:53

I\'m trying to access wikipedia using javascript+CORS

As far as I know, wikipedia should support CORS: http://www.mediawiki.org/wiki/API:Cross-site_requests

5条回答
  •  一整个雨季
    2020-12-01 06:11

    As of today, Wikipedia supports CORS requests by using the normal ajax requests (no need of JSONP/callback manipulation). This can be done by setting the origin in the API call.

    For authenticated requests, this must match the one of the one of the "origins" in the Origin header exactly (you need to set this using the beforeSend property while making an ajax call).
    For unauthenticated requests, you can simply set it as an asterisk (*), and it works when using a simple $.getJSON from your domain. Example api call:
    https://en.wikipedia.org//w/api.php?action=opensearch&format=json&origin=*&search=stack&limit=10
    More at the MediaWiki API sandbox: MediaWiki API sandbox

提交回复
热议问题