Multiple XMLHTTPREQUESTS and Queuing...

Discussion in 'ASP General' started by blueapricot416@gmail.com, Apr 16, 2006.

  1. Guest

    Hello helpful computer people!

    I can't seem to get more than one request to fire simultaneously... and
    I have read there should be at least 2 possible (in IE) and more in
    Firefox.

    I made a demo based on this article/code "Handling Multiple
    XMLHTTPRequest Objects" at
    http://www.drakware.com/articles/multijax.php, which does make mutliple
    requests, but never two seem to happen at the same time.

    See my demo at:

    http://s161149005.onlinehome.us/DEMOS/AJAX/1/multiple_03a.htm

    Hit a bunch of buttons and see how they start "sending", but always
    "answer back" in order. If there were 2 calls happening
    simultaneously, the shorter calls (Button C, which does only "5
    Calculations/Loops") would "jump" over the longer calls when it
    answered back.

    1. Am I missing something? (Or am I right, there is only one request
    happening at a time)
    2. Can I do anything to get more than one XMLHTTPRequest going at a
    time?
    3. Could this be a server issue? (Maybe ASP/IIS has a limit on the
    backend?)

    Thanks for any help. I just started doing the Ajax stuff, and thought
    I saw a world of opportunity, but if I can't get more than one thread
    at a time I don't know how much use it will be to me...

    Thanks for any comments/help,
    Blue Apricot
     
    , Apr 16, 2006
    #1
    1. Advertising

  2. Guest

    If it helps, here is some code. There are 3 files, a normal HTML page
    that has the buttons, an external Javascript file (see below), and a
    simple ASP file that does some dummy calculations to "waste time" and
    then sends a Response.Write back to the page that started things...

    Here is the .js:

    function update_log(t,num)
    {
    document.getElementById('put_here').innerHTML =
    document.getElementById('put_here').innerHTML +
    ' <br>' + t + ' [# of connections: ' + parseInt(xmlreqs.length+num)
    +']'
    }

    function sendData(l,x)
    {
    update_log('<b><i>Button "' + l + '" clicked, Sending
    Request</i></b>',1)
    var queryString = 'AJXloops=' + x + '&AJXaction=' + l
    var url="respond_main_03a.asp";
    xmlreqPOST(url,queryString)
    }

    //
    ------------------------------------------------------------------------------------------------
    // Based on Code from http://www.drakware.com/articles/multijax.php
    //
    ------------------------------------------------------------------------------------------------

    var xmlreqs = new Array();

    function CXMLReq(type, xmlhttp)
    {
    this.type = type;
    this.xmlhttp = xmlhttp;
    }

    function xmlreqGET(url)
    {
    var xmlhttp=false;
    if (window.XMLHttpRequest)
    {
    // Mozilla, etc.
    xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange = xmlhttpChange;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    }
    // IE
    else if (window.ActiveXObject)
    {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    if(! xmlhttp)
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange = xmlhttpChange;
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    }
    }
    var xmlreq = new CXMLReq('', xmlhttp);
    xmlreqs.push(xmlreq);
    }



    function xmlreqPOST(url,data)
    {
    var xmlhttp=false;
    if (window.XMLHttpRequest)
    {
    // Mozilla etc.
    xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=xmlhttpChange;
    xmlhttp.open("POST",url,true);
    xmlhttp.setRequestHeader("Content-Type",
    "application/x-www-form-urlencoded");
    xmlhttp.send(data);
    }
    else if (window.ActiveXObject)
    {
    // IE
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=xmlhttpChange;
    xmlhttp.open("POST",url,true);
    xmlhttp.setRequestHeader("Content-Type",
    "application/x-www-form-urlencoded");
    xmlhttp.send(data);
    }
    }

    var xmlreq = new CXMLReq('', xmlhttp);
    xmlreqs.push(xmlreq);
    }


    function xmlhttpChange()
    {
    if (typeof(window['xmlreqs']) == "undefined") return;

    for (var i=0; i < xmlreqs.length; i++)
    {
    if (xmlreqs.xmlhttp.readyState == 4)
    {
    if (xmlreqs.xmlhttp.status == 200 || xmlreqs.xmlhttp.status ==
    304)
    {
    // 200 OK
    update_log(xmlreqs.xmlhttp.responseText,-1)
    xmlreqs.splice(i,1); i--;
    }
    else
    {
    // error
    xmlreqs.splice(i,1); i--;
    alert("A problem occurred!");
    }
    }
    }
    }
     
    , Apr 16, 2006
    #2
    1. Advertising

  3. Do you jhave debugging enabled on your ASP application? If so it will only
    process one request at a time. So your second request remains in the request
    queue at server until the first request is finished.

    Anthony.

    <> wrote in message
    news:...
    > If it helps, here is some code. There are 3 files, a normal HTML page
    > that has the buttons, an external Javascript file (see below), and a
    > simple ASP file that does some dummy calculations to "waste time" and
    > then sends a Response.Write back to the page that started things...
    >
    > Here is the .js:
    >
    > function update_log(t,num)
    > {
    > document.getElementById('put_here').innerHTML =
    > document.getElementById('put_here').innerHTML +
    > ' <br>' + t + ' [# of connections: ' + parseInt(xmlreqs.length+num)
    > +']'
    > }
    >
    > function sendData(l,x)
    > {
    > update_log('<b><i>Button "' + l + '" clicked, Sending
    > Request</i></b>',1)
    > var queryString = 'AJXloops=' + x + '&AJXaction=' + l
    > var url="respond_main_03a.asp";
    > xmlreqPOST(url,queryString)
    > }
    >
    > //
    > --------------------------------------------------------------------------

    ----------------------
    > // Based on Code from http://www.drakware.com/articles/multijax.php
    > //
    > --------------------------------------------------------------------------

    ----------------------
    >
    > var xmlreqs = new Array();
    >
    > function CXMLReq(type, xmlhttp)
    > {
    > this.type = type;
    > this.xmlhttp = xmlhttp;
    > }
    >
    > function xmlreqGET(url)
    > {
    > var xmlhttp=false;
    > if (window.XMLHttpRequest)
    > {
    > // Mozilla, etc.
    > xmlhttp=new XMLHttpRequest();
    > xmlhttp.onreadystatechange = xmlhttpChange;
    > xmlhttp.open("GET",url,true);
    > xmlhttp.send(null);
    > }
    > // IE
    > else if (window.ActiveXObject)
    > {
    > xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    > if(! xmlhttp)
    > xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    > if (xmlhttp)
    > {
    > xmlhttp.onreadystatechange = xmlhttpChange;
    > xmlhttp.open("GET",url,true);
    > xmlhttp.send();
    > }
    > }
    > var xmlreq = new CXMLReq('', xmlhttp);
    > xmlreqs.push(xmlreq);
    > }
    >
    >
    >
    > function xmlreqPOST(url,data)
    > {
    > var xmlhttp=false;
    > if (window.XMLHttpRequest)
    > {
    > // Mozilla etc.
    > xmlhttp=new XMLHttpRequest();
    > xmlhttp.onreadystatechange=xmlhttpChange;
    > xmlhttp.open("POST",url,true);
    > xmlhttp.setRequestHeader("Content-Type",
    > "application/x-www-form-urlencoded");
    > xmlhttp.send(data);
    > }
    > else if (window.ActiveXObject)
    > {
    > // IE
    > xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    > if (xmlhttp)
    > {
    > xmlhttp.onreadystatechange=xmlhttpChange;
    > xmlhttp.open("POST",url,true);
    > xmlhttp.setRequestHeader("Content-Type",
    > "application/x-www-form-urlencoded");
    > xmlhttp.send(data);
    > }
    > }
    >
    > var xmlreq = new CXMLReq('', xmlhttp);
    > xmlreqs.push(xmlreq);
    > }
    >
    >
    > function xmlhttpChange()
    > {
    > if (typeof(window['xmlreqs']) == "undefined") return;
    >
    > for (var i=0; i < xmlreqs.length; i++)
    > {
    > if (xmlreqs.xmlhttp.readyState == 4)
    > {
    > if (xmlreqs.xmlhttp.status == 200 || xmlreqs.xmlhttp.status ==
    > 304)
    > {
    > // 200 OK
    > update_log(xmlreqs.xmlhttp.responseText,-1)
    > xmlreqs.splice(i,1); i--;
    > }
    > else
    > {
    > // error
    > xmlreqs.splice(i,1); i--;
    > alert("A problem occurred!");
    > }
    > }
    > }
    > }
    >
     
    Anthony Jones, Apr 16, 2006
    #3
  4. Guest

    >Do you jhave debugging enabled on your ASP application?

    Hmmm, how can I find out?

    I didn't change any settings or put in code that I think would enable
    debugging, but I am not sure how to do it, so could it have been done
    by default? Or on a standard IIS install?

    Blue Apricot
     
    , Apr 16, 2006
    #4
  5. <> wrote in message
    news:...
    > >Do you jhave debugging enabled on your ASP application?

    >
    > Hmmm, how can I find out?
    >
    > I didn't change any settings or put in code that I think would enable
    > debugging, but I am not sure how to do it, so could it have been done
    > by default? Or on a standard IIS install?
    >
    > Blue Apricot
    >


    No you'd have to turn it on deliberately.

    Open properties of the application folder or web site, select home directory
    tab and open the application configuration dialog. On the App Debugging
    page if any of the debugging flags are checked then debugging is enabled for
    the application.

    When debugging is enabled there is only a single worker thread to process
    requests. Hence multiple requests will get queued.

    But of course I'm being really dumb ("nothing new there!" I hear a few
    snigger)...

    Requests to ASP pages by the same session will have to be serialised. The
    Session state object is a Single Threaded object it can't be shared by two
    requests being processed simultaneously. You might try the App Options tab
    of the Application Configuration dialog and turn off 'Enable session state'
    that will probably help I've not tried it myself. Of course if you need
    session state then you're stuck but I think this will help prove your AJAX
    stuff.

    Anthony.
     
    Anthony Jones, Apr 16, 2006
    #5
  6. Guest

    Thanks Anthony,
    I turned off 'Enable session state' and my Ajax stuff is working now.
    Thanks for walking me through that.

    One final quick question (sorry)...

    What will be the impact of turning off session state?

    Can I still use session variables, for instance?
    Will it effect stuff in my Global.asa file?

    Thanks so much,
    Blue Apricot
     
    , Apr 16, 2006
    #6
  7. <> wrote in message
    news:...
    > Thanks Anthony,
    > I turned off 'Enable session state' and my Ajax stuff is working now.
    > Thanks for walking me through that.
    >
    > One final quick question (sorry)...
    >
    > What will be the impact of turning off session state?
    >
    > Can I still use session variables, for instance?


    Nope session variables will not be available

    > Will it effect stuff in my Global.asa file?


    Application events and the application object should continue as normal.

    I've not tried it but I suspect the session events won't run at all
    (otherwise they'd have to run for every request and that would be
    undesirable).


    >
    > Thanks so much,
    > Blue Apricot
    >
     
    Anthony Jones, Apr 16, 2006
    #7
  8. Guest

    Thank you very much for your answers, Anthony. You have been a great
    help.

    I really appreciate it. :)

    Blue Apricot
     
    , Apr 16, 2006
    #8
    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. Ohaya
    Replies:
    11
    Views:
    283
    Sylvain Lafontaine
    Feb 25, 2004
  2. Martin

    Are XmlHttpRequests being cached?

    Martin, Mar 31, 2005, in forum: Javascript
    Replies:
    1
    Views:
    115
    Martin Honnen
    Mar 31, 2005
  3. Eric S Johansson

    serialized XMLHttpRequests

    Eric S Johansson, Jan 26, 2006, in forum: Javascript
    Replies:
    19
    Views:
    261
  4. Replies:
    7
    Views:
    164
  5. Replies:
    4
    Views:
    131
    whiskey
    Mar 12, 2007
Loading...

Share This Page