rnicholus
asked on
Ajax xmlHttpObject.open() call works in Mozilla but not in IE
I have a piece of javascript code for Ajax requests that works great in Mozilla but not in IE.
The main method that will be called is getSpeed()
It seems the error in IE is at the point when I call: xmlHttpObject.open(....
The IE throws "Unknown runtime error"
I'm new at Ajax and not sure what I'm doing wrong. Can someone please advise?
Thanks in advance for all the help.
The main method that will be called is getSpeed()
It seems the error in IE is at the point when I call: xmlHttpObject.open(....
The IE throws "Unknown runtime error"
I'm new at Ajax and not sure what I'm doing wrong. Can someone please advise?
Thanks in advance for all the help.
var xmlHttpObject = getXmlHttpRequestObject();
/**
* Create XMLHttpRequestObject.
**/
function getXmlHttpRequestObject()
{
var xmlHttp;
try
{
alert("// Firefox, Opera 8.0+, Safari");
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ alert("// Internet Explorer");
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
} // end catch
} // end catch
} // end catch
alert("xmlHttp:" + xmlHttp);
return xmlHttp;
} // end function
/**
* Called when the AJAX response is returned
**/
function handleResponse()
{
// Check to make sure our response is ready
if (xmlHttpObject.readyState == 4)
{
//alert('responseText:' + xmlHttpObject.responseText);
document.getElementById('speedResultTable').innerHTML=xmlHttpObject.responseText;
//$('#speedResultTable').flexigrid({height:auto});
} // end if
} // end function
/**
* Get speed data.
*/
function getSpeed()
{
alert("startTimeToBeSent: " + startTimeToBeSent +
", endTimeToBeSent: " + endTimeToBeSent +
", pairIdToBeSent: " + pairIdToBeSent
);
document.getElementById('speedResultTable').innerHTML='<tr><td><img src="img/ajax-loader.gif"></td></tr>';
alert("xmlHttpObject:" + xmlHttpObject);
xmlHttpObject.open("GET",
'getSpeed.jsp?startTime=' + startTimeToBeSent +
'&endTime=' + endTimeToBeSent +
'&pairing=' + pairIdToBeSent, true);
alert("call handle response");
// This line will be called when we receive our AJAX response.
xmlHttpObject.onreadystatechange = handleResponse;
xmlHttpObject.send(null);
} // end function
copy and paste the following:
var xmlHttpObject = getXmlHttpRequestObject();
/**
* Create XMLHttpRequestObject.
**/
function getXmlHttpRequestObject()
{
var xmlHttp=null;
try
{
alert("// Firefox, Opera 8.0+, Safari");
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ alert("// Internet Explorer");
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
} // end catch
} // end catch
} // end catch
alert("xmlHttp:" + xmlHttp);
return xmlHttp;
} // end function
/**
* Called when the AJAX response is returned
**/
function handleResponse()
{
// Check to make sure our response is ready
if (xmlHttpObject.readyState == 4)
{
//alert('responseText:' + xmlHttpObject.responseText);
document.getElementById('speedResultTable').innerHTML=xmlHttpObject.responseText;
//$('#speedResultTable').flexigrid({height:auto});
} // end if
} // end function
/**
* Get speed data.
*/
function getSpeed()
{
alert("startTimeToBeSent: " + startTimeToBeSent +
", endTimeToBeSent: " + endTimeToBeSent +
", pairIdToBeSent: " + pairIdToBeSent
);
document.getElementById('speedResultTable').innerHTML='<tr><td><img src="img/ajax-loader.gif"></td></tr>';
alert("xmlHttpObject:" + xmlHttpObject);
if(!xmlHttpObject)return false;
// This line will be called when we receive our AJAX response.
xmlHttpObject.onreadystatechange = handleResponse;
xmlHttpObject.open("GET",
'getSpeed.jsp?startTime=' + encodeURIComponent(startTimeToBeSent )+
'&endTime=' + encodeURIComponent(endTimeToBeSent) +
'&pairing=' + encodeURIComponent(pairIdToBeSent, true));
alert("call handle response");
xmlHttpObject.send(null);
} // end function
ASKER
Here's what I found. It's very weird:
Keep testing for a while and then the "Unknown Runtime Error" happens here:
document.getElementById('s peedResult Table').in nerHTML='< tr><td><im g src="img/ajax-loader.gif"> </td></tr> ';
Then I tried removing the "tr" and "td":
document.getElementById('s peedResult Table').in nerHTML='< img src="img/ajax-loader.gif"> ';
Suddenly the problem disappear.
I put the "tr" and "td" back just out of curiosity. There's no more problem.
I'm confused. =(
Keep testing for a while and then the "Unknown Runtime Error" happens here:
document.getElementById('s
Then I tried removing the "tr" and "td":
document.getElementById('s
Suddenly the problem disappear.
I put the "tr" and "td" back just out of curiosity. There's no more problem.
I'm confused. =(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hielo,
thanks for your explanation.
thanks for your explanation.
Open in new window