js跨域请求

使用js跨域请求资源时报错如下:

XMLHttpRequest cannot load https://en.wikipedia.org/w/api.php?format=json&action=query&generator=searc…racts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
阅读 2.6k
2 个回答

具体想问什么呢?

比如在域名A里 请求域名B。
法1、B服务器响应header里增加Access-Control-Allow-Origin:域名A,表示允许A请求;
法2、jsonp,这个需要请求URL增加个callback,URL接口的返回值也需要稍作修改。具体你查查jsonp的使用吧。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题