我正在使用Apache httpd服务器来托管客户端文件。
http://ipaddress:8010/
我的Nodejs服务器运行在http://ipaddress:8087
当我发送POST请求时,会显示以下错误:
XMLHttpRequest cannot load http://ipaddress:8010/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ipaddress:8087' is therefore not allowed access.
我的客户端代码是:
$.ajax({
type: "POST",
url: "http://ipaddress:8010",
data: {name:"xyz"},
success: function(){
alert("success");
},
dataType: "json"
});
我的服务器端是:
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
response.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
response.setHeader('Access-Control-Allow-Credentials', true);
虽然允许了选项,但它仍然无法工作。有人能建议一下具体问题是什么吗?我在服务器端收到请求,但无法发送任何响应。
提前感谢:)