Hello Everybody,
I am trying to develop code to use the correct version of XMLHTTP and
use it to send SOAP envelope to WebService . The code works fine for the
first time but then after that I get an error that objHttp(XMLHTTP ) is
null or not an object. Pls guide where I am going wrong?
Rahil
<script language="jscri pt">
var objXmlDoc;
var objHttp;
var bDocument=false ;
var bHttp= false;
var interval=1000;
var aszHttpProgIDs;
function getWebServiceRe sultsAfterInit( )
{
// Must be using IE for this to work
if(window.Activ eXObject)
{
// Create the XML Document object
var aszDocumentProg IDs=[ "MSXML2.DOMDocu ment.4.0",
"MSXML2.DOMDocu ment.3.0",
"MSXML2.DOMDocu ment",
"MSXML.DOMDocum ent",
"Microsoft.XmlD om"];
for(var k=0; !bDocument && k<aszDocumentPr ogIDs.length; k++)
{
if (bDocument==fal se)
{
try{
objXmlDoc=new ActiveXObject(a szDocumentProgI Ds[k]);
bDocument=true;
if(bDocument==t rue)
{
alert(bDocument );
}
}
catch (objException)
{
// error handling elided for clarity
}
}// End of if(bDocument==f alse)
} // End of For Loop
try
{
if(bDocument==f alse)
{
throw "MSXML not found on your computer.";
return;
}
} // End of Try
catch(er)
{
if(er=="MSXML not found on your computer.")
alert("Please contact system Administrator") ;
} //End of catch
init();
} // End of If statement
} // End of function
function getxmlhttp()
{
if(window.Activ eXObject)
{
aszHttpProgIDs=["MSXML2.XMLHTTP .4.0",
"MSXML2.XMLHTTP .3.0",
"MSXML2.XMLHTTP ",
"Microsoft.XMLH TTP"];
for ( var i=0;!bHttp && i<aszHttpProgID s.length; i++)
{
if(bHttp==false )
{
try
{
objHttp= new ActiveXObject(a szHttpProgIDs[i]);
bHttp=true;
if(bHttp==true)
{
alert(bHttp);
}
}
catch (objException)
{
// error handling elided for clarity
}
}
}// End of For Loop
try
{
if(bHttp==false )
{
throw "MSXML not found on your computer.";
return;
}
} // End of Try
catch(er)
{
if(er=="MSXML not found on your computer.")
alert("Please contact system Administrator") ;
} //End of catch
go();
}// End of window.ActiveXO bject
} // End of Function
function init()
{
sEnvelope= " <soap:Envelop e
xmlns:xsi=\"htt p://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"htt p://www.w3.org/2001/XMLSchema\"
xmlns:soap=\"ht tp://schemas.xmlsoap .org/soap/envelope/\">";
sEnvelope += "<soap:Body >";
sEnvelope += "<GetUserQu eue
xmlns=\"http://tempuri.org//PBXService\">";
sEnvelope += " <userName>kshah </userName>";
sEnvelope += " <phoneNumber>ks hah</phoneNumber>";
sEnvelope += " <remoteYN>N</remoteYN>";
sEnvelope += " </GetUserQueue>";
sEnvelope += " </soap:Body>";
sEnvelope += "</soap:Envelope>" ;
go();
}
function go(){setTimeout (callWebService ,interval);}
function callWebService( )
{
getxmlhttp() ;
objHttp.onready statechange = objHttp_change;
objHttp.open("P ost","http://ecpcrm/services/pbxservice.asmx ");
objHttp.setRequ estHeader("Cont ent-Type", "text/xml; charset=utf-8");
objHttp.setRequ estHeader("SOAP Action",
"http://tempuri.org//PBXService/GetUserQueue");
objHttp.send(sE nvelope);
}
function objHttp_change( )
{
if (objHttp.readys tate != 4)
return;
// Try to parse the XML string into DOM object
objXmlDoc.loadX ML(objHttp.resp onseText);
alert(objHttp.r esponseText);
test.innerText =
objXmlDoc.selec tSingleNode("//GetUserQueueRes ult").text;
alert(test.inne rText);
objHttp = null;
go();
}
</script>
</head>
<body onload= getWebServiceRe sultsAfterInit( ) >
<form id="Form1" method="post" runat="server">
</form>
<span id="test"></span>
</body>
</html>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!