gpt4 book ai didi

internet-explorer-8 - XMLHttpRequest open() 返回访问被拒绝

转载 作者:行者123 更新时间:2023-12-05 00:41:45 24 4
gpt4 key购买 nike

我对 xhr open() 方法有问题。我的代码如下:

var xmlhttp=false;

if(!xmlhttp)
try
{
xmlhttp=new XMLHttpRequest();
}
catch(e)
{
xmlhttp=false;
}

function returnPage(url)
{
if(!xmlhttp)
return alert("Your browser doesn't seem to support XMLHttpRequests.");

xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState!=4) return;
if(!xmlhttp.status||xmlhttp.status==200)
alert(xmlhttp.responseText);
else
alert("Request failed!");
}; //onreadystatechange

xmlhttp.send(null);
}

称呼 :
<a href='#' onclick="returnPage('http://www.something.com'); return false;">Link 1</a></p>

我正在使用 IE8(因为我正在构建网络切片)并且收到错误“拒绝访问”。我在 Internet 上发现问题在于 XHR 不能跨不同域工作,但我使用了 Firefox Add-on 中的代码,该代码工作正常。并且该附加组件和“我的”代码(相同)正在调用同一个页面。该附加组件如何访问而我的代码没有?

最佳答案

您正在对与您的站点相同的域进行 AJAX 调用的域吗?您不能向其他域发出请求。

编辑 :

Firefox 附加组件具有提升的权限(因为用户必须安装它们)。这就是附加组件可以发出跨域请求的原因。

关于internet-explorer-8 - XMLHttpRequest open() 返回访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2708795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com