VBscript异步XMLHttp调用 [英] VBscript Asynchronous XMLHttp Call

查看:133
本文介绍了VBscript异步XMLHttp调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在处理的项目,我正在尝试进行异步XMLHTTP调用. 我正在使用以下代码:

for a project I'm working on I'm attempting to do a Asynchronous XMLHTTP Call. I'm using the following code:

soapmessage = _
"<?xml version='1.0' encoding='utf-8'?>"& vbcrlf& vbcrlf & _
"<soap:Envelope"& vbcrlf & _
" xmlns:xsi="&chr(34)&"http://www.w3.org/2001/XMLSchema-instance"&chr(34)& 
vbcrlf & _
" xmlns:xsd="&chr(34)&"http://www.w3.org/2001/XMLSchema"&chr(34)& vbcrlf & _
" xmlns:soap="&chr(34)&"http://www.w3.org/2003/05/soap-
envelope"&chr(34)&">"& vbcrlf & _
" <soap:Body>"& vbcrlf & _
"<notification>"& vbcrlf & _
"   <action>Action</action>"& vbcrlf & _
"   <objectid>333333</objectid>"& vbcrlf & _
"</notification>"& vbcrlf & _
" </soap:Body>" & vbcrlf & _
" </soap:Envelope>"

strEndpoint = "**********"

Set xmlhttp = CreateObject("MSXML2.SERVERXMLHTTP.6.0")
xmlhttp.open "POST", strEndpoint, True
xmlhttp.OnReadyStateChange = doHttpOnReadyStateChange()
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.Send soapmessage

Function doHttpOnReadyStateChange()
    If xmlhttp.ReadyState = 4 Then
        'do something
    End If
End Function

当我尝试执行此操作时,我得到以下信息:

When I try to execute this I get the following:

test.vbs(19,1)Microsoft VBScript运行时错误:类型 不匹配:"xmlhttp.OnReadyStateChange"

test.vbs(19, 1) Microsoft VBScript runtime error: Type mismatch: 'xmlhttp.OnReadyStateChange'

知道我可能做错了什么吗? 这是我第一次尝试异步调用,所以我对OnReadyStateChange感到困惑

any idea what I could be doing wrong? It's my first time trying an async call so i'm a bit puzzled with the OnReadyStateChange

推荐答案

它需要一个函数引用,您可以使用

It needs a function reference which you can get using the GetRef() function.

xmlhttp.OnReadyStateChange = GetRef("doHttpOnReadyStateChange")

Dirk.R:想在此修复的同时添加它.请记住,语句的顺序也很重要!

Dirk.R: Would like to add that while this is the fix. Keep in mind that the order of the statements also matters!

这篇关于VBscript异步XMLHttp调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆