其实有很多例子,我用过其中之一。但它是异步的,我的意思是它不会等待我调用完成的函数。如何使用vbscript(同步)调用Web服务?
function ProcessSend()
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.4.0")
Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
oXMLHTTP.onreadystatechange = getRef("HandleStateChange")
strEnvelope = "callNo="&callNo&"&exp="&exp
call oXMLHTTP.open("POST","http://localhost:11883/ServiceCall.asmx/"&posFirm,true)
call oXMLHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
call oXMLHTTP.send(strEnvelope)
end function
Sub HandleStateChange
if(oXMLHTTP.readyState = 4) then
dim szResponse: szResponse = oXMLHTTP.responseText
call oXMLDoc.loadXML(szResponse)
if(oXMLDoc.parseError.errorCode <> 0) then
'call msgbox("ERROR")
response = oXMLHTTP.responseText&" "&oXMLDoc.parseError.reason
'call msgbox(oXMLDoc.parseError.reason)
else
response = oXMLDoc.getElementsByTagName("string")(0).childNodes(0).text
end if
end if
End Sub
我在JavaScript函数中调用ProcessSend函数。它连接到webservice,并返回“响应”变量。但是我的javascript函数不会等待ProcessSend函数的结果。 我如何使它同步?
你在浏览器中或在Windows脚本主办?如果你在浏览器中,为什么你使用一半的JavaScript,一半的VBScript? – Tomalak 2009-02-13 12:58:48