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

Arguments accessible by .always(), .done() and .fail() from jQuery.ajax()? #49

Closed
alano999 opened this issue Jul 29, 2012 · 17 comments
Closed
Assignees

Comments

@alano999
Copy link

Now that .always(), .done() and .fail() are the preferred methods for implementing callbacks from a jQuery.ajax() invocation, and the old methods have been deprecated, it might be a good time to explain the arguments accessible by each of the new methods, and additionally the .then() and .pipe() when applied to jQuery.ajax() invocations?

When browsing the jQuery documentation on api.jquery.com, the available arguments are not listed anywhere, nor are they immediately obvious from elsewhere on the site.

Please would you consider improving the jQuery documentation - for the benefit of other developers who, like myself, cannot see how things work without delving into a debug session? Perhaps you could include the methods clearly within the listing of jQuery.ajax(), noting that the methods are implementations of Deferred and included here for clarity only?

Perhaps you could add a brief section immediately beneath the main properties/functions listing of jQuery.ajax(), showing definitively what arguments are available to each method's callbacks. I am guessing that the arguments are thus, and perhaps this is how they could be shown (once you have confirmed that my guesses are correct!)?:-


_Methods_ (part of jqXHR and Deferred implementations, shown here for clarity only)

.ajax().always(function(a, textStatus, b){});
Replaces method .complete() which was deprecated in jQuery 1.8.
In response to successful transaction, arguments are same as .done() (ie. a = data, b = jqXHR) and for failed transactions the arguments are same as .fail() (ie. a = jqXHR, b = errorThrown).
This is an alternative construct for the complete callback function above. Refer to deferred.always() for implementation details.

.ajax().done(function(data, textStatus, jqXHR){});
Replaces method .success() which was deprecated in jQuery 1.8.
This is an alternative construct for the success callback function above. Refer to deferred.done() for implementation details.

.ajax().fail(function(jqXHR, textStatus, errorThrown){});
Replaces method .error() which was deprecated in jQuery 1.8.
This is an alternative construct for the complete callback function above. Refer to deferred.fail() for implementation details.

.ajax().then(function(data, textStatus, jqXHR){}, function(jqXHR, textStatus, errorThrown){});
Incorporates the functionality of .done() and .fail() methods.
Refer to deferred.then() for implementation details.

.ajax().pipe(function(data, textStatus, jqXHR){}, function(jqXHR, textStatus, errorThrown){});
Incorporates the functionality of .done() and .fail() methods, allowing the underlying Promise to be manipulated.
Refer to deferred.pipe() for implementation details.


My guesswork may be incorrect? This perhaps illustrates the need to improve the documentation within jQuery.ajax().

Hope you can do something to improve documentation.

Kind regards,
Alan
(edited to note that .complete(), .error() and .success() have already been deprecated, and to explain the use of .then() and .pipe() with .ajax())

@roostah
Copy link

roostah commented Dec 7, 2012

+1
JQuery documentation is generally quite good - but, this is one area where it needs to be updated.

@AndreasPresthammer
Copy link

+1
I'm having the same trouble finding this documentation.

@kswedberg
Copy link
Member

I realize this is a glaring omission. Sorry for the delay in updating the documentation. I'll get to it by the end of the week (and if if don't, feel free to scream and holler).

@ghost ghost assigned kswedberg Dec 12, 2012
@dalila-taleb
Copy link

Screaming and hollering...

I'm going to get the pitchforks :-)

@kswedberg
Copy link
Member

Thanks, @dalila-taleb. Working on it now. :)

@peterrow
Copy link

Please reopen this - the documentation is still badly formed. The docs for done(), always() etc.. should describe the params for the function. The page for .ajax is already long winded and I missed the above snippet that reproduced in alano999's post.

@kswedberg
Copy link
Member

@peterrow It would be really helpful if you could create a new issue and possibly reference this one.

@peterrow
Copy link

@kswedberg - done

@axos88
Copy link

axos88 commented Jun 24, 2015

+1, it should be documented in the always, done, etc as well.

@Flimm
Copy link

Flimm commented Oct 2, 2015

+1

1 similar comment
@xDaizu
Copy link

xDaizu commented Nov 16, 2015

+1

@brenoperucchi
Copy link

1+

@ghost
Copy link

ghost commented Feb 24, 2016

How can I test the fail scenario of post method.
I am using perl script for on server end.
I have already tried die, exit & return with multiple parameters but I always get success as status.

@dmethvin
Copy link
Member

@abhisina That is a StackOverflow question.

@architchandra
Copy link

I'm a beginner, so might be wrong, but I am facing a lot of problems trying to understand how to use the methods related to $.ajax and deferred objects. At every step, I'm having to scour StackOverflow. The documentation on these fields is not well-suited for people who already don't have a thorough understanding. Would be grateful if fixed.

@leefogel
Copy link

👍

@damien-roche
Copy link

damien-roche commented Jul 13, 2018

Save yourself the headache and use https://github.com/axios/axios.

Been using jQuery for 5 years and yet here I am, yet again scouring for this information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet