JavaScript
Article

.success() and .error() still supported in jQuery 1.9.1

By Sam Deering

Just a quick note that you can still use .success() and .error() in jQuery 1.9.1 and it won’t break your code. I do however highly recommend using the new promise interface with callback methods .done() and .fail() – See AJAX before jQuery 1.8 and After on code differences.

They have backwards compatiability in jQuery 1.9.1. Let’s look at the source pay attention to the alias lines.

//http://code.jquery.com/jquery-latest.js (v1.9.1)

// Attach deferreds (line 7835-7838)
deferred.promise( jqXHR ).complete = completeDeferred.add;
jqXHR.success = jqXHR.done;
jqXHR.error = jqXHR.fail;

//...

// Install callbacks on deferreds  (line 7951-7954)
for ( i in { success: 1, error: 1, complete: 1 } ) {
  jqXHR[ i ]( s[ i ] );
}

//...

// Success/Error (line 8072-8077)
if ( isSuccess ) {
  deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
} else {
  deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
}

No Reader comments

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.