Multiple XMLHTTPREQUESTS and Queuing...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • blueapricot416@gmail.com

    Multiple XMLHTTPREQUESTS and Queuing...

    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:



    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

  • blueapricot416@gmail.com

    #2
    Re: Multiple XMLHTTPREQUESTS and Queuing...

    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,nu m)
    {
    document.getEle mentById('put_h ere').innerHTML =
    document.getEle mentById('put_h ere').innerHTML +
    ' <br>' + t + ' [# of connections: ' + parseInt(xmlreq s.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_ma in_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.XMLHttp Request)
    {
    // Mozilla, etc.
    xmlhttp=new XMLHttpRequest( );
    xmlhttp.onready statechange = xmlhttpChange;
    xmlhttp.open("G ET",url,true) ;
    xmlhttp.send(nu ll);
    }
    // IE
    else if (window.ActiveX Object)
    {
    xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
    if(! xmlhttp)
    xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
    if (xmlhttp)
    {
    xmlhttp.onready statechange = xmlhttpChange;
    xmlhttp.open("G ET",url,true) ;
    xmlhttp.send();
    }
    }
    var xmlreq = new CXMLReq('', xmlhttp);
    xmlreqs.push(xm lreq);
    }



    function xmlreqPOST(url, data)
    {
    var xmlhttp=false;
    if (window.XMLHttp Request)
    {
    // Mozilla etc.
    xmlhttp=new XMLHttpRequest( );
    xmlhttp.onready statechange=xml httpChange;
    xmlhttp.open("P OST",url,true) ;
    xmlhttp.setRequ estHeader("Cont ent-Type",
    "applicatio n/x-www-form-urlencoded");
    xmlhttp.send(da ta);
    }
    else if (window.ActiveX Object)
    {
    // IE
    xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
    if (xmlhttp)
    {
    xmlhttp.onready statechange=xml httpChange;
    xmlhttp.open("P OST",url,true) ;
    xmlhttp.setRequ estHeader("Cont ent-Type",
    "applicatio n/x-www-form-urlencoded");
    xmlhttp.send(da ta);
    }
    }

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


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

    for (var i=0; i < xmlreqs.length; i++)
    {
    if (xmlreqs[i].xmlhttp.readyS tate == 4)
    {
    if (xmlreqs[i].xmlhttp.status == 200 || xmlreqs[i].xmlhttp.status ==
    304)
    {
    // 200 OK
    update_log(xmlr eqs[i].xmlhttp.respon seText,-1)
    xmlreqs.splice( i,1); i--;
    }
    else
    {
    // error
    xmlreqs.splice( i,1); i--;
    alert("A problem occurred!");
    }
    }
    }
    }

    Comment

    • Anthony Jones

      #3
      Re: Multiple XMLHTTPREQUESTS and Queuing...

      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.

      <blueapricot416 @gmail.com> wrote in message
      news:1145154622 .004145.152110@ u72g2000cwu.goo glegroups.com.. .[color=blue]
      > 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,nu m)
      > {
      > document.getEle mentById('put_h ere').innerHTML =
      > document.getEle mentById('put_h ere').innerHTML +
      > ' <br>' + t + ' [# of connections: ' + parseInt(xmlreq s.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_ma in_03a.asp";
      > xmlreqPOST(url, queryString)
      > }
      >
      > //
      > --------------------------------------------------------------------------[/color]
      ----------------------[color=blue]
      > // Based on Code from http://www.drakware.com/articles/multijax.php
      > //
      > --------------------------------------------------------------------------[/color]
      ----------------------[color=blue]
      >
      > var xmlreqs = new Array();
      >
      > function CXMLReq(type, xmlhttp)
      > {
      > this.type = type;
      > this.xmlhttp = xmlhttp;
      > }
      >
      > function xmlreqGET(url)
      > {
      > var xmlhttp=false;
      > if (window.XMLHttp Request)
      > {
      > // Mozilla, etc.
      > xmlhttp=new XMLHttpRequest( );
      > xmlhttp.onready statechange = xmlhttpChange;
      > xmlhttp.open("G ET",url,true) ;
      > xmlhttp.send(nu ll);
      > }
      > // IE
      > else if (window.ActiveX Object)
      > {
      > xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
      > if(! xmlhttp)
      > xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
      > if (xmlhttp)
      > {
      > xmlhttp.onready statechange = xmlhttpChange;
      > xmlhttp.open("G ET",url,true) ;
      > xmlhttp.send();
      > }
      > }
      > var xmlreq = new CXMLReq('', xmlhttp);
      > xmlreqs.push(xm lreq);
      > }
      >
      >
      >
      > function xmlreqPOST(url, data)
      > {
      > var xmlhttp=false;
      > if (window.XMLHttp Request)
      > {
      > // Mozilla etc.
      > xmlhttp=new XMLHttpRequest( );
      > xmlhttp.onready statechange=xml httpChange;
      > xmlhttp.open("P OST",url,true) ;
      > xmlhttp.setRequ estHeader("Cont ent-Type",
      > "applicatio n/x-www-form-urlencoded");
      > xmlhttp.send(da ta);
      > }
      > else if (window.ActiveX Object)
      > {
      > // IE
      > xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
      > if (xmlhttp)
      > {
      > xmlhttp.onready statechange=xml httpChange;
      > xmlhttp.open("P OST",url,true) ;
      > xmlhttp.setRequ estHeader("Cont ent-Type",
      > "applicatio n/x-www-form-urlencoded");
      > xmlhttp.send(da ta);
      > }
      > }
      >
      > var xmlreq = new CXMLReq('', xmlhttp);
      > xmlreqs.push(xm lreq);
      > }
      >
      >
      > function xmlhttpChange()
      > {
      > if (typeof(window['xmlreqs']) == "undefined" ) return;
      >
      > for (var i=0; i < xmlreqs.length; i++)
      > {
      > if (xmlreqs[i].xmlhttp.readyS tate == 4)
      > {
      > if (xmlreqs[i].xmlhttp.status == 200 || xmlreqs[i].xmlhttp.status ==
      > 304)
      > {
      > // 200 OK
      > update_log(xmlr eqs[i].xmlhttp.respon seText,-1)
      > xmlreqs.splice( i,1); i--;
      > }
      > else
      > {
      > // error
      > xmlreqs.splice( i,1); i--;
      > alert("A problem occurred!");
      > }
      > }
      > }
      > }
      >[/color]


      Comment

      • blueapricot416@gmail.com

        #4
        Re: Multiple XMLHTTPREQUESTS and Queuing...

        >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

        Comment

        • Anthony Jones

          #5
          Re: Multiple XMLHTTPREQUESTS and Queuing...


          <blueapricot416 @gmail.com> wrote in message
          news:1145204363 .282115.263670@ i39g2000cwa.goo glegroups.com.. .[color=blue][color=green]
          > >Do you jhave debugging enabled on your ASP application?[/color]
          >
          > 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
          >[/color]

          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.


          Comment

          • blueapricot416@gmail.com

            #6
            Re: Multiple XMLHTTPREQUESTS and Queuing...

            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

            Comment

            • Anthony Jones

              #7
              Re: Multiple XMLHTTPREQUESTS and Queuing...


              <blueapricot416 @gmail.com> wrote in message
              news:1145212635 .239202.308620@ i39g2000cwa.goo glegroups.com.. .[color=blue]
              > 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?[/color]

              Nope session variables will not be available
              [color=blue]
              > Will it effect stuff in my Global.asa file?[/color]

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

              [color=blue]
              >
              > Thanks so much,
              > Blue Apricot
              >[/color]



              Comment

              • blueapricot416@gmail.com

                #8
                Re: Multiple XMLHTTPREQUESTS and Queuing...

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

                I really appreciate it. :)

                Blue Apricot

                Comment

                Working...