我对IE有一个问题(只有IE8+,Chrome工作得很好),当我试图将信息发布到我的网站上的另一个页面时,我发现了一个错误:“访问控制中找不到http://localhost:7230 -允许-开始标题”。我知道这在某种程度上与CORS有关,但我不会离开我的领域。
发送请求的页面是:http://localhost:7230/TestPage.aspx
我想要发布到http://localhost:7230/ActionHandler.aspx的页面
要发布到页面的代码:
function RequestData()
{
//If we have no data don't request anything, just reset the timer
if (dataStore.topReadings.length == 0 && dataStore.specifiedRanges.length == 0 && dataStore.entireRanges.length == 0 && dataStore.periodRanges.length == 0)
{
setInterval(RequestData, options.interval);
}
var params = "?Action=GET_DATA";
var body = GetRequestXML();
var xmlhttp;
if (window.XDomainRequest) // code for IE8 and IE9
{
xmlhttp = new XDomainRequest();
if (xmlhttp)
{
xmlhttp.onerror = function ()
{
alert("[Data Config]Failed to send request for configuration!\n" + xmlhttp.responseText);
};
xmlhttp.ontimeout = function ()
{
alert('xdr ontimeout');
};
xmlhttp.onprogress = function ()
{
};
xmlhttp.onload = function ()
{
if (xmlhttp.responseText)
{
HandleResponseData($($.parseXML(xmlhttp.responseText)));
}
};
} else
{
alert('failed to create xdr');
}
}
else
{
if (window.XMLHttpRequest) // code for IE7, Firefox, Chrome, Opera, Safari
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
alert("[Data Request]Failed to create XMLHTTPRequest!\n" + e.message);
}
}
else // code for IE6, IE5
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function ()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
//alert("Handled!");
HandleResponseData($($.parseXML(xmlhttp.responseText)));
that.trigger("dataReceived");
}
}
}
try
{
xmlhttp.timeout = options.timeout;
xmlhttp.open("POST", "http://localhost:7230/ActionHandler.aspx" + params, true);
}
catch (e)
{
alert("[Data Request]Failed to open XMLHTTPRequest!\n" + e.message);
}
setTimeout(function () { xmlhttp.send(body); }, 0);
}这是一个在visual中运行的ASP.NET网站。我遵循了这里步骤,并将相关的行添加到web.config文件中。任何有关如何将我的请求传递到ActionHandler页面的帮助都将不胜感激。
发布于 2013-09-04 22:34:54
通常,如果您从一个域发布到另一个域,或者您从http源发布到https端点,甚至在同一个域上,您都会看到这一点。
你试过设置这个标题吗?
Access-Control-Allow-Origin", "*"显然,使用*有点太宽泛了,您可能想缩小范围,但是看看这是否解决了您的问题。
https://stackoverflow.com/questions/18624746
复制相似问题