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

ajaxSubmit does not expose nor return handle to ajax promise #234

Closed
AndrewRayCode opened this issue Sep 25, 2012 · 4 comments
Closed

ajaxSubmit does not expose nor return handle to ajax promise #234

AndrewRayCode opened this issue Sep 25, 2012 · 4 comments

Comments

@AndrewRayCode
Copy link

http://api.jquery.com/jQuery.ajax/#jqXHR

The jqXHR objects returned by $.ajax() as of jQuery 1.5
implement the Promise interface, giving them all the
properties, methods, and behavior of a Promise (see
Deferred object for more information)

So in normal jquery code you can do

$.ajax({ ... }).then(function() { ... }).done(function() { ... }).fail(function() { ... })
$.post({ ... }).then(function() { ... }).done(function() { ... }).fail(function() { ... })
// etc

Promises are very powerful and jQuery has adopted them as their core async flow control. An async jQuery form plugin that mimics the ajax method seems like it should return one or a way to get it. From browsing the code I don't see any exposed ajax objects.

Since ajaxSubmit takes the same arguments as $.ajax so it seems very logical that it would return a promise object instead of the form element, or expose a way to get it. $form.ajaxSubmit().promise() does not work since it's only grabbing the form element's deferred object.

malsup added a commit that referenced this issue Sep 25, 2012
@malsup
Copy link
Collaborator

malsup commented Sep 25, 2012

Made a quick change to allow access to the jqxhr. The plugin will now add a property to the settings object called 'jqxhr' and that will be available in callbacks, like beforeSend. I can't change the return type on that method because it is and always has been a plugin method that returns a jQuery object. This change isn't ideal, I know.

@AndrewRayCode
Copy link
Author

Could you give an example usage to access it with your above changeset?

What about another jquery.fn like .ajaxSubmitPromise() so you could do $form.ajaxSubmit().ajaxSubmitPromise().then... ? Just a thought.

@malsup
Copy link
Collaborator

malsup commented Sep 29, 2012

jqxhr object is now stored in element data. Example: http://jquery.malsup.com/form/deferred.php

@malsup malsup closed this as completed Sep 29, 2012
@playmono
Copy link

playmono commented Mar 7, 2019

We are using ajaxSubmit in our projects and since we are migrating to new standard Javascript and good practises, is a pity this cant be implemented :(.

If someone has a nice and clean workaround we are here to listen :)

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

3 participants