Synchronous JScript POST functions?

Discussion in 'Javascript' started by Brad, Feb 2, 2005.

  1. Brad

    Brad Guest

    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?
    Brad, Feb 2, 2005
    #1
    1. Advertising

  2. Brad wrote:

    > 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.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Feb 2, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Maz
    Replies:
    4
    Views:
    1,259
    Jon Maz
    Sep 9, 2004
  2. Maxwell2006
    Replies:
    5
    Views:
    2,385
    Steven Cheng[MSFT]
    Mar 7, 2006
  3. Rickert
    Replies:
    0
    Views:
    654
    Rickert
    Oct 6, 2011
  4. John Bentley
    Replies:
    14
    Views:
    342
    Jim Ley
    Feb 5, 2004
  5. VK
    Replies:
    4
    Views:
    350
    Thomas 'PointedEars' Lahn
    Jan 12, 2006
Loading...

Share This Page