Ajax核心:XMLHTTP组件相关技术资料2
点击次数:28 次 发布日期:2008-11-26 11:06:14 作者:源代码网
|
源代码网推荐 源代码网推荐 setRequestHeader bstrHeader, bstrValue 源代码网推荐 源代码网推荐 bstrHeader:HTTP 头(header) 源代码网推荐 源代码网推荐 bstrValue:HTTP 头(header)的值 源代码网推荐 源代码网推荐 如果Open方法定义为POST,可以定义表单方式上传xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 源代码网推荐 源代码网推荐 XMLHTTP属性 源代码网推荐 源代码网推荐 onreadystatechange:在同步执行方式下获得返回结果的事件句柄。只能在DOM中调用。 源代码网推荐 源代码网推荐 responseBody:结果返回为无符号整数数组。 源代码网推荐 源代码网推荐 responseStream:结果返回为IStream流。 源代码网推荐 源代码网推荐 responseText :结果返回为字符串。 源代码网推荐 源代码网推荐 responseXML:结果返回为XML格式数据。 源代码网推荐 源代码网推荐 下面是本文附件源程序中的一个应用示例: 源代码网推荐 源代码网推荐 Function GetResult(urlStr) 源代码网推荐 源代码网推荐 Dim xmlHttp 源代码网推荐 源代码网推荐 Dim retStr 源代码网推荐 源代码网推荐 Set xmlHttp = CreateObject("Msxml2.XMLHTTP") "创建对象 源代码网推荐 源代码网推荐 On Error Resume Next "出错处理 源代码网推荐 源代码网推荐 xmlHttp.Open "POST", urlStr, False "用POST方式打开连接,异步执行。 源代码网推荐 源代码网推荐 xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" "上传表单 源代码网推荐 源代码网推荐 xmlHttp.Send "发送指令 源代码网推荐 源代码网推荐 If Err.Number = 0 Then "如果连接正确 源代码网推荐 源代码网推荐 retStr = xmlHttp.responseText "等待并获得服务端返回的结果字符串 源代码网推荐 源代码网推荐 Else 源代码网推荐 源代码网推荐 retStr = "Url not found" "否则返回出错信息 源代码网推荐 源代码网推荐 End If 源代码网推荐 源代码网推荐 Set xmlHttp = nothing "释放对象 源代码网推荐 源代码网推荐 GetResult = retStr "返回结果 源代码网推荐 源代码网推荐 End Function 源代码网推荐 源代码网推荐 GetResult()函数带入一个服务网页的URL参数,把上传的指令安放在URL后面的参数上,如: 源代码网推荐 源代码网推荐 urlStr = "server.asp?cmd=" & cmd & "&db=" & db & "table=" & table 源代码网推荐 源代码网推荐 cmd:执行方式,例如查询,修改,删除等等。 源代码网推荐 源代码网推荐 db:服务端数据库名 源代码网推荐 源代码网推荐 table:服务端表名 源代码网推荐 源代码网推荐 然后提交指令,等待并接收返回的处理结果。结果以字符串方式返回。最后由函数调用者处理并显示结果。 源代码网推荐 http://blog.csdn.net/daniao2003/archive/2007/01/29/1496908.aspx 源代码网推荐 做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。 源代码网推荐 源代码网供稿. |
