netsmithcentral
asked on
Synchronus XML Request
Often when I'm programming, I find I would be much better served by a synchronus XML HTTP request than an asynchronus one. For instance, if I'm doing a postback from a popup window I want to close as soon as the data is retrieved, an asynchronus request just won't work properly.
Up until now, I've been using a "magic button" with it's click event registered to an asyncronus version of the function call I want to make, and then calling triggering the click via script before closing the window (this avoids orphaning the XMLHttpObject before any asynchronus callback requests are made).
Now, Ideally, I want to just return the result of a synchronus request DIRECTLY from the calling function... that is, no "onreadystatechange" (callback) function.
Up until now, I've been using a "magic button" with it's click event registered to an asyncronus version of the function call I want to make, and then calling triggering the click via script before closing the window (this avoids orphaning the XMLHttpObject before any asynchronus callback requests are made).
Now, Ideally, I want to just return the result of a synchronus request DIRECTLY from the calling function... that is, no "onreadystatechange" (callback) function.
put the window close in the function that is called on the return of your post back... That fakes a sync call... if you do a sync call you might as well just have a standard form and post it to the back cause it's gonna lock up all other processes... You should be able to change the boolean value on the open to make it sync. set it to false.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you are dealing directly with the XMLHttp object (or MS equivalent) you can simply pass false as the third argument in the .open() method.
I.e.
xhr.open('GET', 'http://example.com/ajax', false); //synchronous
xhr.open('GET', 'http://example.com/ajax', true[or omitted]); //asynchronous
<a href="http://developer.apple.com/internet/webcontent/xmlhttpreq.html">Great Resource!</a>
I.e.
xhr.open('GET', 'http://example.com/ajax', false); //synchronous
xhr.open('GET', 'http://example.com/ajax', true[or omitted]); //asynchronous
<a href="http://developer.apple.com/internet/webcontent/xmlhttpreq.html">Great Resource!</a>
doh, thought i could do a standard link :(