AJAX request waiting on other concurrent requests

Discussion in 'JavaScript' started by ScottAN, Jul 30, 2008.

  1. #1
    I have a server monitoring system that is fully AJAX. There is one xmlhttprequest object created when the page loads and it is used to check for new server status updates. The currently displayed information is POSTed to the script and it checks to see if there are any new updates. If not, the script will sleep for 20 seconds and try again, if there are new updates it will return the new alerts.

    The problem is whenever this AJAX request is still loading any other xmlhttprequests will wait until the other status checking thread returns a value. Any idea why this is happening? For all other requests a new xmlhttprequest object is created so none are reused.

    Thanks in advance for the help!
     
    ScottAN, Jul 30, 2008 IP
  2. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Javascript is the problem, it is single threaded. it can only do one thing at a time when javascript is running all other prcesses are paused until it completes.
     
    Sleeping Troll, Jul 30, 2008 IP
  3. ScottAN

    ScottAN Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the xmlhttp objects can be processed at the same time when the async option is set to true. In that case the request will be sent off and other JS can be processed and when the state of the request changes it will run the function set for the xmlhttprequest.onreadystatechange value.
     
    ScottAN, Jul 31, 2008 IP