Thanks, Rupak, but I was hoping to be able to accomplish this without a
plugin. What I'm thinking of doing is storing the XMLHttpRequest object as a
local variable early on, like in the beforeSend callback.
var xmlHttpRequest = null;

$.ajax({
    /* ... */
    beforeSend: function(request)
    {
        xmlHttpRequest = request;
    }
});

$.('button.canel').click(function(event)
{
    if (null !== xmlHttpRequest) {
        xmlHttpRequest.abort();
        xmlHttpRequest = null;
    }
    event.preventDefault();
});

I am not sure if this would cause any issues with the overall ajax
lifecycle. For example, if the cancel button was clicked, would the "error"
callback be executed? I'll have to test it and see.

--
Hector


On Tue, Aug 25, 2009 at 9:00 PM, rupak mandal <rupakn...@gmail.com> wrote:

> Hi Hector,
> you have to use abort function.
>
> go through this link http://www.protofunc.com/scripts/jquery/ajaxManager/
>
>
> Thanks
> Rupak
>
>
> On Wed, Aug 26, 2009 at 2:25 AM, Hector Virgen <djvir...@gmail.com> wrote:
>
>> Hello,
>> Is there a way to stop or cancel an ajax request on demand, similar to
>> pressing "stop" in the browser? I would like to provide the user with a
>> cancel button on a "loading" dialog that, when clicked, closes the dialog
>> and cancels the ajax request. I have the dialog working (thanks to
>> jQuery-UI) but pressing cancel only closes the it.
>>
>> I do not want simply ignore the response because I have a "success"
>> callback that does some heavy manipulation of the response HTML that I'd
>> like to prevent from running when the user cancels.
>>
>> Any help would be appreciated. Thanks!
>>
>> --
>> Hector
>>
>
>

Reply via email to