Hi,

> I thought of something like this:
>
> currentRequest = new Ajax.Request(
>   onSuccess: function(transport) {
>        if (transport.request == currentRequest)
>        {
>            alert(this response matches the last request)
>        }
>    }

I'd use === rather than ==, but yes, the docs[1] say that
Ajax.Response has a 'request' property, and looking at the code it
looks like it's the same request instance that generated the response.

You can go a step further by trying to proactive cancel the first
request:
* * * *
/* ==== Where you create the request ==== */
// If we have a previous active request and can cancel it, do so
if (currentRequest && currentRequest.transport &&
currentRequest.transport.stop) {
    currentRequest.transport.stop();
}
currentRequest = new Ajax.Request(... {
    onSuccess: function(response) {
        if (response.request === currentRequest) {
            // It's the current one
        }
    }
});
* * * *

XHR2 has a stop method which is implemented by most modern browsers.
Ajax.Request's 'transport' property is not documented and could change
or disappear in any Prototype release, but for now it's there and it's
the XHR object.

[1] http://prototypejs.org/api/ajax/response

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On May 1, 8:06 pm, oddvark <[email protected]> wrote:
> Hey I have a situation where the user might make a number of requests
> before individual responses come in.  I'd like to make it so that if
> the user makes a second request before the first one comes it, it
> cancels or ignores the first one.    I thought of something like this:
>
> currentRequest = new Ajax.Request(
>   onSuccess: function(transport) {
>        if (transport.request == currentRequest)
>        {
>            alert(this response matches the last request)
>        }
>    }
>
> }
>
> Is there a better way to do this?  Can I compare by urls?
>
> thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to