Saturday, February 28, 2009

[jQuery] Re: forcing ajax request to stop

sure, the $.ajax method returns the xhr object, and you can call the
abort method of it. Something like follows:

var xhr = $.ajax(...);
xhr.abort();

Regards,
svpino.


On Feb 23, 1:12 pm, Adam <epne...@gmail.com> wrote:
> Hey, I'm looking for a way to force some known running ajax requests
> to stop before initiating another call..
>
> I'm using the jQuery.ajax global events to monitor the active
> requests.. but in the jQuery docs, i was unable to find a method of
> forcing a processing request to actually stop...
>
> For example, in this case, if someone starts a "search" request.. but
> then changes there mind and wants to submit different request, I want
> the currently processing "search" request to be forced to stop before
> allowing the second search to be sent to my back end....
>
> The only way i can see this happening, is to build into my backend
> request a method of recieving a "stop" message, and then abborting the
> back end call, thus forcing the request to stop..
>
> Does anyone know of a way of doing this with just jQuery or perhaps
> the XHR object?

No comments: