[英]IE XdomainRequest CORS issue
我遇到了IE问题(仅IE8 +,Chrome可以正常工作),当我尝试将信息发布到网站上的另一个页面时,我收到一条错误消息,指出“在Access-中找不到原始http://localhost:7230
Control-Allow-Origin标头”。 我了解这在某种程度上与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 Studio中运行的ASP.NET网站。 我已按照此处的步骤进行操作,并将相关行添加到了我的web.config文件中。 我们将非常感谢您提供有关如何将我的请求发送到ActionHandler页面的任何帮助。
通常,如果您是从一个域发布到另一个域,或者是从http
源发布到https
端点(即使在同一域上),也会看到此消息。
您是否尝试设置此标头?
Access-Control-Allow-Origin", "*"
显然,使用*
范围太广了,您需要缩小范围,但是看看是否可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.