简体   繁体   English

CORS AJAX呼叫失败

[英]CORS AJAX Call not Successful

I have an AJAX call trying to execute the following CORS request to a Web Server (I am currently testing using only the latest version of Chrome): 我有一个AJAX调用,试图对Web服务器执行以下CORS请求(我目前仅使用最新版本的Chrome进行测试):

var xhr = new XMLHttpRequest();
xhr.open("get", "http://www.web_server_url.com/query", true);
xhr.onload = function(){
};
xhr.send(null);

Meanwhile, I am still getting the following message: 同时,我仍然收到以下消息:

XMLHttpRequest cannot load http://www.web_server_url.com/query. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

Would someone know what I am missing? 有人知道我在想什么吗?

The reason is exactly what it says in the error: The server at www.web_server_url.com is not allowing the localhost origin. 原因与错误中的内容完全相同: www.web_server_url.com上的服务器不允许localhost来源。 It's up to the server to decide whether to allow the origin of the call. 由服务器决定是否允许呼叫源。 In this case, apparently it's not allowing it. 在这种情况下,显然是不允许的。

The way CORS works, the server replies to the request (or a "preflight" request) with headers either allowing or disallowing the origin on the basis of the information the browser sends it. CORS的工作方式是,服务器根据浏览器发送给它的信息,使用标头来允许或禁止源头,从而回复请求(或“预检”请求)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM