Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP wait/sleep

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
I have an asp function that makes use of the XMLHttpRequest object. This HTTP call to an external page takes a while to process. Despite setting the final parameter of this line

Code:
objHTTP.open "POST", "[URL unfurl="true"]http://www.foobar.com",[/URL] False

to false, ie don't make the call asynchronously and wait until the call returns before continuing, I still can see that the process often does not complete and that it returns to the calling ASP script and continues. So if this object does not wait, can I make this function wait or sleep?

Code:
'Very often my foobar customer gets his boo value set but not his foo value as the foo() call does not get enough time to process.

' sets foo value to 'a'
foo(foobarid)
' sets boo value to 'b'
boo(foobarid)

Function foo(foobarid)
 Set objHTTP = CreateObject("Microsoft.XMLHTTP")
 objHTTP.open "POST", "[URL unfurl="true"]http://www.foobar.com",[/URL] False 
 objHTTP.setRequestHeader "Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
 objHTTP.send "foobarid=" & server.URLEncode(foobarid)  
 Set objHTTP = Nothing
 
Try set timeout. Something like
Code:
   setTimeout "PollServer", 1000, "vbsccript"

...
sub PollServer ()
   ... check for reply
   if no reply then
      setTimeout "PollServer", 1000, "vbscript"
   end if
end sub
 
It has been waiting from within the function foo, only that you do nothing with the response either within the function or through some out-parameter or global variable to modify the external world. To repeat, time has been spent to wait for the response, no need with additional sleep.
 
By "[tt][or] global variable to modify the external world[/tt]", I mean you set objHTTP immediately to nothing. If you don't, the following script lines would be able to reference to it and use the response object of it as it is a global variable, however good or bad the design as shown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top