【发布时间】:2023-03-26 09:54:01
【问题描述】:
我正在使用 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);
允许的选项仍然无法正常工作任何人都可以提出究竟是什么问题? 我在服务器端接收请求,但无法发送任何响应。
提前感谢:)
【问题讨论】:
标签: javascript jquery json node.js post