本文介绍了XMLHttpRequest无法加载.所请求的资源上没有"Access-Control-Allow-Origin"标头.因此,不允许访问原点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用apache httpd服务器托管客户端文件

I am using apache httpd server for hosting client side files

http://ipaddress:8010/

并且我的Nodejs服务器在http://ipaddress:8087

and my Nodejs server is running on http://ipaddress:8087

当我发送帖子请求时,它显示以下错误

when i am sending post request then it shows following error

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);

允许的选项仍然不起作用,有人可以提示问题出在哪里吗? 我在服务器端收到请求,但无法发送任何响应.

options allowed still it is not working can anybody suggest what exactly is the problem? i am receiving request on server side but not able to send any response.

提前感谢:)

推荐答案

错误消息显示:

您已经设置了三个Access-Control-Allow-SOMETHING标头,但都不是Origin.

You have set three Access-Control-Allow-SOMETHING headers, but none of them is Origin.

这篇关于XMLHttpRequest无法加载.所请求的资源上没有"Access-Control-Allow-Origin"标头.因此,不允许访问原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 01:25