Dear All
I am trying to create an instance of XMLHTTPRequest, but it return null in Mozila firefox, safari, opera.
Here is my code.
function GetXmlHttpObject()
{
//Purpose : Create XMLHttp Object for different browser type
objHTTP = null;
try
{
if (window.XMLHttpRequest)
{
// If IE7, Mozilla, Safari, etc: Use native object
var objHTTP = new XMLHttpRequest();
}
else
{
if (window.ActiveXObject)
{
try
{
objHTTP=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
// ...otherwise, use the ActiveX control for IE5.x and IE6
var objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
}
}
}
return objHTTP;
}
catch (excep)
{
}
}
is there any mistake in my code. It is workng fine in IE 6 and 7.
Please suggest me.
Thanks
Regards
Ashish
Subject: XMLHttpRequest Object Not supported in Mozila, safari, opera
It shouldn’t work in IE either if the version uses Microsoft.XMLHTTP (IE5) – your use of var inside the if/else block means that the objHTTP variable the function returns is not the same as the one you are setting inside the block. This will work:
function GetXmlHttpObject()
{
//Purpose : Create XMLHttp Object for different browser type
var objHTTP = null;
try
{
if (window.XMLHttpRequest)
{
// If IE7, Mozilla, Safari, etc: Use native object
objHTTP = new XMLHttpRequest();
}
else
{
if (window.ActiveXObject)
{
try
{
objHTTP=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
// ...otherwise, use the ActiveX control for IE5.x and IE6
objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
}
}
}
return objHTTP;
}
catch (excep)
{
}
}
Subject: RE: XMLHttpRequest Object Not supported in Mozila, safari, opera
Thank you Sir,
Does innerText property support by Mozila, Firefox?
my Code:
it does not display the text in Mozila, firefox browser while working on IE.
is any alternative.
Thanks
Regards
Ashish
Subject: RE: XMLHttpRequest Object Not supported in Mozila, safari, opera
No, but innerHTML is.