multiple "ajax" requests

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony

    multiple "ajax" requests

    I've done a fair bit of searching on this, but I want to be certain
    about what I've found - so here goes with a long example and three
    questions:

    For clarity, let me give an example (a number of the pages I found had
    some ambiguity). Say I have a page with 2 buttons ( A and B, for
    simplicity) and each button will make a different "ajax" request, for
    data to be placed in a corresponding DIV.

    For sake of example, we won't consider latency.

    The simple operation, assuming no server-processing time issues: I
    click A and it responds with data for DIV A, click B and it responds
    for DIV B.

    But now let's assume that the processing for A takes 10 seconds, and B
    takes 5 seconds. Also assume that I click these buttons at a rate of 1
    per second (A, B, in that order).

    If I queue the requests, then when I click A, the request takes 10
    seconds to process. When I click B, that request has 9 seconds left to
    process. So the request for B just sits there for 9 seconds until the
    response comes back from A (9 seconds later), THEN the request is sent
    out, and I get my response from B 5 seconds after that, or 14 seconds
    after I clicked on B.

    If I send the requests immediately, then when I click A, it sends out a
    request which takes 10 seconds to process. When I click B, there are 9
    seconds left for A to process. B is done processing 5 seconds later,
    while A still has 4 seconds left. So I should be able to get the
    response back from B, then 4 seconds later get the response for A - so
    even though A is clicked first, the response for B comes back first.

    But I can't seem to make this happen.

    Even if I set up a new 'object' (I know JS doesn't have 'real' objects)
    and keep the requests tied to each individual object, the second
    request cancels the first, so I only get a response to the most
    recently made request.

    Which leads me to question #1 - How do I make two simultaneous requests
    like this? Or can I?

    I also have read that users can generally only have 2 connections open
    at the same time on one client - which leads to question 2: Is it
    better to just forget trying to make simultaneous requests and simply
    queue them?

    And the final question - if I just queue the requests, how, then, would
    that differ from making the requests synchronous?

    Thanx for the input...

  • Dominic Myers

    #2
    Re: multiple "ajax&quot ; requests

    "Tony" <tony23@dslextr eme.com> wrote in message
    news:1140134496 .183766.229690@ g14g2000cwa.goo glegroups.com.. .[color=blue]
    > I've done a fair bit of searching on this, but I
    > want to be certain
    > about what I've found - so here goes with a long
    > example and three
    > questions:
    >
    > For clarity, let me give an example (a number of
    > the pages I found had
    > some ambiguity). Say I have a page with 2
    > buttons ( A and B, for
    > simplicity) and each button will make a
    > different "ajax" request, for
    > data to be placed in a corresponding DIV.
    >
    > For sake of example, we won't consider latency.
    >
    > The simple operation, assuming no
    > server-processing time issues: I
    > click A and it responds with data for DIV A,
    > click B and it responds
    > for DIV B.
    >
    > But now let's assume that the processing for A
    > takes 10 seconds, and B
    > takes 5 seconds. Also assume that I click these
    > buttons at a rate of 1
    > per second (A, B, in that order).
    >
    > If I queue the requests, then when I click A,
    > the request takes 10
    > seconds to process. When I click B, that request
    > has 9 seconds left to
    > process. So the request for B just sits there
    > for 9 seconds until the
    > response comes back from A (9 seconds later),
    > THEN the request is sent
    > out, and I get my response from B 5 seconds
    > after that, or 14 seconds
    > after I clicked on B.
    >
    > If I send the requests immediately, then when I
    > click A, it sends out a
    > request which takes 10 seconds to process. When
    > I click B, there are 9
    > seconds left for A to process. B is done
    > processing 5 seconds later,
    > while A still has 4 seconds left. So I should be
    > able to get the
    > response back from B, then 4 seconds later get
    > the response for A - so
    > even though A is clicked first, the response for
    > B comes back first.
    >
    > But I can't seem to make this happen.
    >
    > Even if I set up a new 'object' (I know JS
    > doesn't have 'real' objects)
    > and keep the requests tied to each individual
    > object, the second
    > request cancels the first, so I only get a
    > response to the most
    > recently made request.
    >
    > Which leads me to question #1 - How do I make
    > two simultaneous requests
    > like this? Or can I?
    >
    > I also have read that users can generally only
    > have 2 connections open
    > at the same time on one client - which leads to
    > question 2: Is it
    > better to just forget trying to make
    > simultaneous requests and simply
    > queue them?
    >
    > And the final question - if I just queue the
    > requests, how, then, would
    > that differ from making the requests
    > synchronous?
    >
    > Thanx for the input...
    >[/color]

    I've been pondering the same thing recently and I
    came across this site
    http://www.mattkruse.com/javascript/ajax/ which
    has a mechanism to do Simultaneous Requests, "The
    demo below illustrates simultaneous requests which
    do not collide with each other. Each button
    requests a script from the server which waits for
    5 seconds, then returns "Done!". Click the buttons
    in any order, at any speed, and the corresponding
    checkboxes will be filled in accordingly.". Thing
    is, since I upgraded to IE7 (it's debatable
    whether it's an upgrade but it does seem to be
    better TBH) it doesn't seem to work anymore...?

    I decided that it was simply better to combine the
    requests and do it all at the same time and then
    fill in the results using the DOM... might not be
    appropriate for you application though?

    Cheers, Dom


    Comment

    • Tony

      #3
      Re: multiple &quot;ajax&quot ; requests

      Dominic Myers wrote:[color=blue]
      >
      > I've been pondering the same thing recently and I
      > came across this site
      > http://www.mattkruse.com/javascript/ajax/ which
      > has a mechanism to do Simultaneous Requests, "The
      > demo below illustrates simultaneous requests which
      > do not collide with each other. Each button
      > requests a script from the server which waits for
      > 5 seconds, then returns "Done!". Click the buttons
      > in any order, at any speed, and the corresponding
      > checkboxes will be filled in accordingly.". Thing
      > is, since I upgraded to IE7 (it's debatable
      > whether it's an upgrade but it does seem to be
      > better TBH) it doesn't seem to work anymore...?[/color]

      Thanx for that - I'll definitely check it out!
      [color=blue]
      > I decided that it was simply better to combine the
      > requests and do it all at the same time and then
      > fill in the results using the DOM... might not be
      > appropriate for you application though?[/color]

      Unfortunately, that won't work - thanx

      Comment

      • Matt Kruse

        #4
        Re: multiple &quot;ajax&quot ; requests

        Dominic Myers wrote:[color=blue]
        > I've been pondering the same thing recently and I
        > came across this site
        > http://www.mattkruse.com/javascript/ajax/[/color]

        Note:
        I meant to remove that page (I will when I get a chance)
        Instead, see http://www.AjaxToolbox.com/

        --
        Matt Kruse




        Comment

        Working...