Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aborting ajax requests #221

Closed
iammartinbelobrad opened this issue Aug 3, 2012 · 4 comments
Closed

Aborting ajax requests #221

iammartinbelobrad opened this issue Aug 3, 2012 · 4 comments

Comments

@iammartinbelobrad
Copy link

Please add ajaxAbort() method or return in your methods ajaxSubmit and ajaxForm XHR object, please. The library does not abort the request.

@StephenChan
Copy link

ajaxSubmit() and ajaxForm() don't return the XHR object, but the XHR object is passed as the first parameter to the beforeSend callback. So you can get the XHR object by specifying a beforeSend callback, and saving that XHR object to a variable in that callback. Then when you want to abort the upload, you can call abort() on that XHR object.

beforeSend is not an option listed in the jQuery Form options list, but it is an option to $.ajax(), and ajaxSubmit()/ajaxForm() take any option that $.ajax() does.

So there is a way to abort the upload, though I think it would be nice if it were better documented than it is now - or if there were a convenient utility function to abort, as you suggested. I was stuck on this for a little while myself, because I initially expected ajaxSubmit()/ajaxForm() to return the XHR object, and I was mainly only looking at the jQuery Form options list instead of the $.ajax() options list. I only found the answer from this issue.

@iammartinbelobrad
Copy link
Author

I do not know, it seems to us more appropriate and logical way return XHR object, like it has with jQuery $.ajax

@andrewharry
Copy link

I would prefer the xhr object returned. Especially seeing as this plug-in is unlikely to be used with chaining.

@malsup
Copy link
Collaborator

malsup commented Dec 18, 2012

The jqHXR is now stored on the form object and is accessible using the data method.

var form = $('#myForm').ajaxSubmit({ ... });
var xhr = form.data('jqxhr');
...

@malsup malsup closed this as completed Dec 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants