1

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

AFellowDevInNeed
  • 11
  • 1
  • 1
  • 2
  • What is it that leads you to believe it is not working? I.e. what error are you getting? – James Wiseman Jul 15 '11 at 15:45
  • Perhaps you destroy the objXMLHTTP to fast so that async call is not finished. Take a look at the setTimeouts Method http://msdn.microsoft.com/en-us/library/ms760403(v=vs.85).aspx – Yots Jul 15 '11 at 16:49
  • @James Wiseman - on the xmlhttp post page, i process some information, write to db and sends an email. Calling page1 contains the code mentioned above which does an async post to page 2. Page 2 never gets called from page 1. I have striped page 1 so it just calls page 2, nothing happens. However if I type in the url of page 2, my page does all the processing and sends an email. – AFellowDevInNeed Jul 15 '11 at 18:00
  • @Yots - placed time out on the obj, still nothing. – AFellowDevInNeed Jul 15 '11 at 18:01
  • possible duplicate of: http://stackoverflow.com/questions/1510497/how-do-i-fire-an-asynchronous-call-in-asp-classic-and-ignore-the-response – ThatGuyInIT Jul 15 '11 at 19:31

1 Answers1

7

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

Garland Pope
  • 3,242
  • 1
  • 25
  • 19
ThatGuyInIT
  • 2,239
  • 17
  • 20
  • 1
    you'll probably want to move "Set objXML = Nothing" to after the send statement – Dee Jul 16 '11 at 03:10
  • 1
    @Dee it can't be after send, because it will close the connection before a response is generated, which is why it is closed in the delegate function. – ThatGuyInIT Jul 16 '11 at 03:35