In Internet Explorer 6 I'm having a problem with the httprequest
object. I use it to call a webservice and display the result in the
readystate event handler. This works the first time I call it but
subsequently the readystate event handler function is never called, or
the event itself is never fired.
The same code works fine in Firefox. Changed it around a lot to no
effect Can anyone help?
I'm not supposed to create a new XmlHttpRequest object every time I
want to call a remote procedure am I?
Hope you don't mind the long post but here's the code it's simple
enough:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
</head>
<script type="text/javascript">
//initiates the XMLHttpRequest object
//as found here: http://www.webpasties.com/xmlHttpRequest
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_vers ion >= 5)
try {
xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try {
xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
try {
xmlhttp = new XMLHttpRequest( );
} catch (e) {
xmlhttp = false;
}
}
alert("instanti ated");
return xmlhttp;
}
var Request = getHTTPObject() ;
function GetTreeOutput()
{
try
{
if( Request != null)
{
if (Request.readyS tate == 4 || Request.readySt ate == 0)
{
var sUrl = "http://itsopt-15/webgame/Service1.asmx/HelloWorld";
Request.onready statechange = GetTreeOutput_R esponse;
Request.open("P OST", sUrl, true);
Request.send(nu ll);
}
}
else
{
}
}
catch( e)
{
}
}
function GetTreeOutput_R esponse()
{
try
{
if( Request.readySt ate == 4)
{
if( Request.status == 200)
{
document.getEle mentById( "test").innerHT ML = Request.respons eText;
}
else
{
}
}
}
catch(e)
{
}
}
</script>
<body>
<input type="button" value="One" onclick="javasc ript:GetTreeOut put();"
/>
<input type="button" value="two" onclick="javasc ript:GetTreeOut put();"
/>
<input type="button" value="Three"
onclick="javasc ript:GetTreeOut put();" />
<div id="test" style="border: 1px solid Black; background-color: #ddf;
color: #003;">
</div>
</body>
</html>