-1

Where in the JQuery Docs are these parameters?

jqXHR.done(function( data, textStatus, jqXHR ) {});

http://api.jquery.com/deferred.done/

For example, I tried searching what data would be and cannot find it.

Also, I see examples like .done( function( msg ){} ) or

// Create a deferred object
var dfd = $.Deferred();
// Add handlers to be called when dfd is resolved
dfd
// .done() can take any number of functions or arrays of functions
.done( [ fn1, fn2 ], fn3, [ fn2, fn1 ] )
// We can chain done methods, too
.done(function( n ) {
$( "p" ).append( n + " we're done." );
});

So I am clearly confused about how the parameters are passed to this function.

I need to get the responseText I think, I am echoing a number in PHP.

Thanks!

3 Answers 3

4

From jQuery .ajax()

A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object.

You want the data; that's your server response.

Sign up to request clarification or add additional context in comments.

3 Comments

What's up with the example I put where .done( function( n ){} ), receives a n parameter? What will it be data?
JS parameters are not required, so whatever you call the first one is the first parameter. In that case n is your data.
So, I will have these parameters available jqXHR.done(function( data, textStatus, jqXHR ) {}); and then I will be able to use them, in order, with any name ?
1

.done is the same as the success callback in your JQuery.ajax properties. The callback is described here: as follows:

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

success Type: Function( PlainObject data, String textStatus, jqXHR jqXHR )

.done takes 1-n functions or arrays of functions which should get invoked on success of your ajax call

data is simply the data you receive as response from the server, some json object...

Comments

0

When you register a callback with a promise's .done() method, this callback will be passed the parameter that this promise will be resolved with: promise.resolve(data). In the case of a jQuery Ajax request, the servers response body is the data that the XHR promise is resolved with.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.