jQuery Chaining and .fail() May 17th, 2013

Examples of using .fail() method to handle errors via chaining…

onSubmitEmailForm: function(e) {
    e.preventDefault();
    if (this.isValid(this.$emailForm)) { 
        $.ajax({ 
            type: 'POST', 
            url: this.$emailForm.attr('action'), 
            data: this.$emailForm.serialize() 
        }).done(_.bind(function(response) { 
            this.$container.hide(); 
            this.$('.email-success').show(); 
            PubSub.trigger('uotrack', 'UtilityBarShareEmail'); 
        }, this)).fail(_.bind(function(response){ 
            alert("Your text did not match the image."); 
        }, this)); 
    } 
},
$.get("test.php")
    .done(function(){ alert("$.get succeeded"); })
    .fail(function(){ alert("$.get failed!"); });

Resources