{"id":2504,"date":"2013-05-17T14:23:33","date_gmt":"2013-05-17T14:23:33","guid":{"rendered":"http:\/\/www.webninjataylor.com\/library\/?p=2504"},"modified":"2014-06-24T21:11:41","modified_gmt":"2014-06-24T21:11:41","slug":"jquery-chaining-and-fail","status":"publish","type":"post","link":"https:\/\/webninjataylor.com\/library\/jquery-chaining-and-fail\/","title":{"rendered":"jQuery Chaining and .fail()"},"content":{"rendered":"<p>Examples of using .fail() method to handle errors via\u00a0chaining&#8230;<\/p>\n<pre>onSubmitEmailForm: function(e) {\r\n    e.preventDefault();\r\n    if (this.isValid(this.$emailForm)) { \r\n        $.ajax({ \r\n            type: 'POST', \r\n            url: this.$emailForm.attr('action'), \r\n            data: this.$emailForm.serialize() \r\n        }).done(_.bind(function(response) { \r\n            this.$container.hide(); \r\n            this.$('.email-success').show(); \r\n            PubSub.trigger('uotrack', 'UtilityBarShareEmail'); \r\n        }, this)).fail(_.bind(function(response){ \r\n            alert(\"Your text did not match the image.\"); \r\n        }, this)); \r\n    } \r\n},<\/pre>\n<pre>$.get(\"test.php\")\r\n    .done(function(){ alert(\"$.get succeeded\"); })\r\n    .fail(function(){ alert(\"$.get failed!\"); });\r\n<\/pre>\n<h2>Resources<\/h2>\n<ul>\n<li><a href=\"http:\/\/api.jquery.com\/deferred.fail\/\" target=\"_blank\">jQuery API<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Examples of using .fail() method to handle errors via\u00a0chaining&#8230; onSubmitEmailForm: function(e) { e.preventDefault(); if (this.isValid(this.$emailForm)) { $.ajax({ type: &#8216;POST&#8217;, url: this.$emailForm.attr(&#8216;action&#8217;), data: this.$emailForm.serialize() }).done(_.bind(function(response) { this.$container.hide(); this.$(&#8216;.email-success&#8217;).show(); PubSub.trigger(&#8216;uotrack&#8217;, &#8216;UtilityBarShareEmail&#8217;); }, this)).fail(_.bind(function(response){ alert(&#8220;Your text did not match the image.&#8221;); }, this)); } }, $.get(&#8220;test.php&#8221;) .done(function(){ alert(&#8220;$.get succeeded&#8221;); }) .fail(function(){ alert(&#8220;$.get failed!&#8221;); }); Resources jQuery API<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[144],"tags":[9,27],"class_list":["post-2504","post","type-post","status-publish","format-standard","hentry","category-web-shots","tag-javascript","tag-jquery"],"_links":{"self":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/2504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/comments?post=2504"}],"version-history":[{"count":8,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/2504\/revisions"}],"predecessor-version":[{"id":3359,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/2504\/revisions\/3359"}],"wp:attachment":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/media?parent=2504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/categories?post=2504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/tags?post=2504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}