Question:
I am using the XMLHTTPRequest object in Visual Basic to invoke an async call. How do I register a complete event handler of the XMLHTTPRequest object?
Answer:
You’re not going to be happy with this answer, but there isn’t any way to register an event handler in VB. The XMLHTTPRequest object doesn’t source the event in Visual Basic?only in a scripting environment. All that the async attribute of the Open command does is turn off blocking when the Send method is invoked. I was a little surprised myself when I discovered this, as it is definitely a bad implementation. Probably the simplest solution in this situation is to poll the XMLHTTP object until its readyState gets set to 4 (i.e., “complete”). This isn’t ideal, but unless you have a browser running within your application and can use the scripting version of the command, you’re basically out of luck.