AJAX: Have to wait for it to complete before proceeding?

Discussion in 'Javascript' started by 1kHz, May 17, 2005.

  1. 1kHz

    1kHz Guest

    Hi all..

    I'm new with this Ajax thingy and have done some experimenting. I did
    some codes according to examples from
    http://www.webpasties.com/xmlHttpRequest/
    and
    http://www.jamesdam.com/ajax_login/login.html

    In my code, I request a PHP page that will iterate 10000 times and
    return a 10000 line of text, and then put it in a DIV. I initiate the
    Ajax from a button click. What I notice is, if I click some other
    hyperlink in the page after clicking the button, it will wait until all
    the Ajax processes are done before going to the link. Is this the norm?
    Where's the "synchronous" part in that? Have I done something wrong?

    These are some snippets from my code:
    -------------------------------------------------
    var req = new XMLHttpRequest();

    function GetContent()
    {
    req.open("GET", "test2.php", true);
    req.onreadystatechange = ReadyStateChange;
    req.send(null);
    }

    function ReadyStateChange()
    {
    var panel = document.getElementById('theDiv');
    if (req.readyState == 4)
    {
    panel.innerHTML = req.responseText;
    }
    }
    -------------------------------------------------

    Thanks..
     
    1kHz, May 17, 2005
    #1
    1. Advertising

  2. 1kHz

    1kHz Guest

    > Where's the "synchronous" part in that? Have I done something wrong?
    Sorry, that should be "asynchronous"..
     
    1kHz, May 17, 2005
    #2
    1. Advertising

  3. 1kHz

    Rich Hephner Guest

    Hi all..


    I'm new with this Ajax thingy and have done some experimenting. I did
    some codes according to examples from
    http://www.webpasties.com/xmlH­ttpRequest/and
    http://www.jamesdam.com/ajax_l­ogin/login.html


    In my code, I request a PHP page that will iterate 10000 times and
    return a 10000 line of text, and then put it in a DIV. I initiate the
    Ajax from a button click. What I notice is, if I click some other
    hyperlink in the page after clicking the button, it will wait until all

    the Ajax processes are done before going to the link. Is this the norm?

    Where's the "synchronous" part in that? Have I done something wrong?


    These are some snippets from my code:
    ------------------------------­-------------------
    var req = new XMLHttpRequest();


    function GetContent()
    {
    req.open("GET", "test2.php", true);
    req.onreadystatechange = ReadyStateChange;
    req.send(null);
    }


    function ReadyStateChange()
    {
    var panel = document.getElementById('theDi­v');
    if (req.readyState == 4)
    {
    panel.innerHTML = req.responseText;
    }
    }
    ------------------------------­-------------------


    Thanks..


    I'm new at this too, but that last argument in req.open is where you
    specify synchronous or asynchronous. I'm betting if you change:

    req.open("GET", "test2.php", true);

    to

    req.open("GET", "test2.php", false);

    You'll get what you need.
     
    Rich Hephner, May 17, 2005
    #3
    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. TJS
    Replies:
    2
    Views:
    708
    Kevin Spencer
    Feb 11, 2004
  2. McGirr, Mark A ILMB:EX

    POpen - Wait For Process To Complete

    McGirr, Mark A ILMB:EX, Dec 20, 2007, in forum: Python
    Replies:
    0
    Views:
    366
    McGirr, Mark A ILMB:EX
    Dec 20, 2007
  3. Luc Vantroys
    Replies:
    8
    Views:
    143
    Eric Armstrong
    Aug 15, 2006
  4. Luc Vantroys
    Replies:
    1
    Views:
    98
    N Okia
    Aug 5, 2006
  5. Replies:
    3
    Views:
    126
Loading...

Share This Page