Synchronous JScript POST functions?

B

Brad

A long-time JScript/IE programmer friend of mine shared a technique
with me recently that puzzles me. He has a series of functions that
perform POSTs, with each function returning a dummy value. He has a
dummy variable in the calling code to catch it. He said that by both
returning and catching this dummy value, the POSTs perform
synchronously, whereas if there were no values caught in the calling
code, they would perform asychronously. Sort of like this:

var dummy1 = PostFunction1();
var dummy2 = PostFunction2();

where each PostFunctionX does a POST, and returns something like
'ignoreMe'.

I looked around and couldn't find any documentation detailing this
technique anywhere. Can someone point me to information about it? Or
shed light on other ways of accomplishing the same thing?
 
M

Martin Honnen

Brad said:
A long-time JScript/IE programmer friend of mine shared a technique
with me recently that puzzles me. He has a series of functions that
perform POSTs, with each function returning a dummy value. He has a
dummy variable in the calling code to catch it. He said that by both
returning and catching this dummy value, the POSTs perform
synchronously, whereas if there were no values caught in the calling
code, they would perform asychronously. Sort of like this:

var dummy1 = PostFunction1();
var dummy2 = PostFunction2();

where each PostFunctionX does a POST, and returns something like
'ignoreMe'.

I looked around and couldn't find any documentation detailing this
technique anywhere. Can someone point me to information about it?

Not really, we need to guess, if you are talking about a HTTP POST then
I guess those functions (e.g. PostFunction1) which you didn't bother to
show us use MSXML (e.g.
var httpRequest = new ActiveXObject('Microsoft.XMLHTTP')
) and then make a HTTP POST request with it, then there is no magic to
it as to whether processing is synchronous or asynchronous, the third
parameter of the open method determines that e.g.
httpRequest.open('POST', 'whatever.php', true);
is asynchronously (preferred way but needs an onreadystatechange event
handler) while
httpRequest.open('POST', 'whatever.php', false);
opens a synchronous requests (not preferred as it blocks the browser but
that gives you a way to have the script wait and return a value).
Docs are on http://msdn.microsoft.com/, look for MSXML.

But as said we need to guess, if those functions use/do something else
then obviously what I told you and pointed to you doesn't help, so
provide some details and then maybe we can identify what is done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top