Archive

Archive for December, 2011

JQuery Parsed Ajax Errors

December 15, 2011 Leave a comment

A very cool code fragment I ran into while looking for something else — funny how that happens.

jQuery Deferreds and the jQuery Promise Method

JQXHR AND THE PROMISE INTERFACE

  1. $.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
  2.   if ( options.parseError ) {
  3.     jqXHR.pipe( null, function( jqXHR, statusText, errorMsg ) {
  4.         var parsed = $.parseJSON( jqXHR.responseText );
  5.         return $.Deferred().rejectWith( this, [ jqXHR, statusText, parsed ] );
  6.     }).promise( jqXHR );
  7.     jqXHR.success = jqXHR.done;
  8.     jqXHR.error = jqXHR.fail;
  9.   }
  10. });

http://lithostech.com/2011/04/jquery-deferreds-and-the-jquery-promise-method/

Advertisements
Categories: Uncategorized