XMLHTTP classic asp Post

筅森魡賤 提交于 2019-12-11 10:25:04

问题


I am working with Classic ASP web application. Goal here is to do a time consuming data processing without having client to wait for a response. That resulted in using xmlhttp object async post. Here is the piece of code that should post to desired URL. I am able to hit this page directly when typing the url, and all data processing is functional, however i am unable to kick start this send request in my vbscript. I opted for VBscript because i am doing validations and making sure data is in desired format prior to xmlhttp post versus calling in javascript. I am jammed here for a while now, and truly will appreciate your help.

Dim objXMLHTTP
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.Open "POST", "myurl", true
objXMLHTTP.Send
Set objXMLHTTP = nothing

-aFellowDevInNeed


回答1:


If you're doing async, you will need a delegate function to handle the state change of the request. When readyState is 4, the request was sent to the server and a full response was received. We also check to make sure that the request was HTTP 200 OK; otherwise, there may have been an error, or we received a partial response from the server:

Dim objXML
Function objXML_onreadystatechange()
    If (objXML.readyState = 4) Then
        If (objXML.status = 200) Then
            Response.Write(objXML.responseText)
            Set objXML = Nothing
        End If
    End If
End Function

Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
Call objXML.open("POST", "http://localhost/test.asp", True)
objXML.onreadystatechange = GetRef("objXML_onreadystatechange")
objXML.send()

This all being said, doing an async call in Classic ASP is not 100%. If the user aborts the request by hitting Stop, Refresh, or closes their browser, the request will be considered aborted.

http://msdn.microsoft.com/en-us/library/ms535874(v=vs.85).aspx



来源:https://stackoverflow.com/questions/6709639/xmlhttp-classic-asp-post

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!