我正在尝试向运行在localhost上的API发送ajax请求,但出现错误
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
http://127.0.0.1:9100/api/banks. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
HTML页面的运行位置:http://localhost/jqmob/
尽管相同的代码在邮递员上工作正常,但如何解决此问题?
var form = new FormData();
form.append("lang", "en");
var settings = {
"async": true,
"crossDomain": true,
"url": "http://127.0.0.1:9100/api/banks",
"method": "POST",
"headers": {
"Cache-Control": "no-cache",
"Postman-Token": "b246c9ad-ce2d-4e39-bbef-5df0af6476e0"
},
"processData": false,
"contentType": false,
"mimeType": "multipart/form-data",
"data": form
}
$.ajax(settings).done(function (response) {
console.log(response);
});
在本地主机的HTML页面中,我使用jQuery 1.11.3
在.htaccess中的API应用中
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>