Cross domain - REST API

Cross domain - REST API

本文关键字:API REST domain Cross      更新时间:2023-09-26

我使用REST API请求JSON文件,然后在JS中的工具中使用它。

以下是我的代码:

$.getJSON(sourcefilename, function(http://restapi/myjson, status, xhr) {

由于跨域重用,我总是收到一个错误:

XMLHttpRequest无法加载http://restapi/myjson.请求的资源上不存在"Access Control Allow Origin"标头。原点'http://127.0.0.1因此不允许访问。响应的HTTP状态代码为400。

我读了很多话题,尝试了一些事情,但我无法回避,我希望有人能帮助我。

我目前正在使用带有easyphp的APACHE。API是JIRA REST API,如果这可以帮助

感谢


这是我的.htaccess文件:

Order deny,allow
allow from 127.0.0.1
deny from all
Header set Access-Control-Allow-Origin "*"

看看http://enable-cors.org/server_apache.html这些是在您的apache服务器上启用CORS所需要经历的步骤。您可以在此处看到支持CORS的浏览器:http://enable-cors.org/client.html.