Forum Moderators: open

Message Too Old, No Replies

Error coming in firefox while trying cross-domain XHR

Error coming in firefox while trying cross-domain XHR

         

RaviK

10:40 am on Feb 8, 2010 (gmt 0)

10+ Year Member



I want to submit the data to another server in some case for this purpose i am using below code. This code is working fine for IE but giving below error in firefox.

============Error Message========================
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: file:///C:/Inetpub/wwwroot/testRavi/test.html :: onLoadfun :: line 31" data: no]

============Javascript code====================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function onLoadfun()
{
var url = "http://example.com/site_name/check.aspx?empId=123456";
xmlhttp=null;
var flag = false;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
try
{
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange = function state_Change()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200){}
}
};
xmlhttp.open("GET",url,false);
xmlhttp.send(null);

if (xmlhttp.status==200)
{
flag = true;
}
}
else
{
alert("Your browser does not support XMLHTTP.");
return;
}
}
catch (e)
{
alert(e);
}

if(flag == true)
{
alert('Operation sucessful')
}
}
</script>
</HEAD>
<BODY onload="onLoadfun();">

</BODY>
</HTML>

[edited by: Fotiman at 2:32 pm (utc) on Feb 8, 2010]
[edit reason] Examplified URL [/edit]

whoisgregg

10:27 pm on Feb 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried running it on a website instead of from your local machine? Browsers can be funny about that when it comes to AJAX because of security concerns.