XMLHttpRequest无法加载,不存在“Access-Control-Allow-Origin”头(在JavaScript / jQuery中无法读取Ajax响应)

问题描述:

我使用jQuery向服务器发送Ajax请求,以下是代码片段。

I'm sending an Ajax request to server using jQuery, below is the code snippet.

$.ajax({                
                type: 'POST',
                url: "https://store.example.com/account?",                
                data: "cf=cw&operation=update"
            })

当然,请求的页面和Ajax请求的URL在同一个域中。仍然,我看到在浏览器控制台中指定的错误消息和JavaScript / jQuery无法读取响应。请帮助我。

Definitely, "requested page" and "Ajax request’s URL" are in same domain. Still, Am seeing specified error message in browser console and unable read response with JavaScript/jQuery. Please help me here.


错误消息:XMLHttpRequest无法加载
https://store.example.com/account ?在请求的资源上不存在Access-Control-Allow-Origin
头。原因
' http://store.example.com '因此不允许访问。

Error message: XMLHttpRequest cannot load https://store.example.com/account?. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://store.example.com' is therefore not allowed access.


请求页面和请求的网址是否在同一个域中。您可以尝试使用相对路径访问网址吗?

Are the requesting page and requested URL are in the same domain. Can you try accessing the url using relative path?

$.ajax({                
            type: 'POST',
            url: "/account?",                
            data: "cf=cw&operation=update"
        })