javascript XDomainRequest 上的访问被拒绝错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8464262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access is denied error on XDomainRequest
提问by narek.gevorgyan
I'm trying to use microsoft XDomainRequest to send cross domain request. Here is the code
我正在尝试使用 microsoft XDomainRequest 发送跨域请求。这是代码
... if ($.browser.msie && window.XDomainRequest) { // Use Microsoft XDR var xdr = new XDomainRequest(); xdr.open("POST", "http://graph.facebook.com/1524623057/"); xdr.send(); } ....
... if ($.browser.msie && window.XDomainRequest) { // Use Microsoft XDR var xdr = new XDomainRequest(); xdr.open("POST", "http://graph.facebook.com/1524623057/"); xdr.send(); } ....
It gives SCRIPT5: Access is denied.
error on xdr.open(...)
line.
它在线给出SCRIPT5: Access is denied.
错误 xdr.open(...)
。
回答by narek.gevorgyan
I found the reason of this problem. As stated in Point 7:
我找到了这个问题的原因。如第 7 点所述:
Requests must be targeted to the same scheme as the hosting page
This restriction means that if your AJAX page is at
http://example.com
, then your target URL must also begin with HTTP. Similarly, if your AJAX page is athttps://example.com
, then your target URL must also begin with HTTPS.
请求必须针对与托管页面相同的方案
此限制意味着,如果您的 AJAX 页面位于
http://example.com
,则您的目标 URL 也必须以HTTP开头。同样,如果您的 AJAX 页面位于https://example.com
,那么您的目标 URL 也必须以HTTPS开头。
回答by dnuttle
See this:
看到这个:
http://msdn.microsoft.com/en-us/library/cc288060(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/cc288060(v=vs.85).aspx
It describes how the server must respond with a certain header, Access-Control-Allow-Origin.
它描述了服务器必须如何响应某个标头 Access-Control-Allow-Origin。