I'm having an issue with IE (only IE8+, Chrome works just fine) where when I try to post information to another page on my website I get an error saying that "Origin http://localhost:7230
not found in Access-Control-Allow-Origin header". I understand this has to do with CORS in some way but I'm no going outside of my domain.
The page that sends the request is: http://localhost:7230/TestPage.aspx
The page I am trying to post to http://localhost:7230/ActionHandler.aspx
The code to post to the page:
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);
}
This is an ASP.NET website running in visual studio. I've followed the steps here and added the relevant lines to my web.config file. Any help on how to get my requests through to the ActionHandler page would be greatly appreciated.
Normally you'll see this if you're posting from one domain to another or if you're posting from an
http
source to anhttps
end point even on the same domain.Have you tried setting this header?
Obviously using
*
is a bit too broad and you'll want to narrow but see if that fixes your issue.