{"id":142,"date":"2026-08-10T19:11:05","date_gmt":"2026-08-10T19:11:05","guid":{"rendered":"https:\/\/api.jquery.com\/?p=142"},"modified":"2026-08-10T19:11:05","modified_gmt":"2026-08-10T19:11:05","slug":"deferred.always","status":"publish","type":"post","link":"https:\/\/api.jquery.com\/deferred.always\/","title":{"rendered":"deferred.always()"},"content":{"rendered":"<article id=\"deferred-always1\" class=\"entry method\"><h2 class=\"section-title\">\n<span class=\"name\">deferred.always( alwaysCallbacks [, alwaysCallbacks ] )<\/span><span class=\"returns\">Returns: <a href=\"http:\/\/api.jquery.com\/Types\/#Deferred\">Deferred<\/a><\/span>\n<\/h2>\n<div class=\"entry-wrapper\">\n<p class=\"desc\"><strong>Description: <\/strong> Add handlers to be called when the Deferred object is either resolved or rejected. <\/p>\n<ul class=\"signatures\"><li class=\"signature\">\n<h4 class=\"name\">\n<span class=\"version-details\">version added: <a href=\"\/category\/version\/1.6\/\">1.6<\/a><\/span><a id=\"deferred-always-alwaysCallbacks-alwaysCallbacks\" href=\"#deferred-always-alwaysCallbacks-alwaysCallbacks\"><span class=\"icon-link\"><\/span>deferred.always( alwaysCallbacks [, alwaysCallbacks ] )<\/a>\n<\/h4>\n<ul>\n<li id=\"deferred-always-alwaysCallbacks-alwaysCallbacks-alwaysCallbacks\">\n<div><strong>alwaysCallbacks<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#Function\">Function<\/a>()<\/div>\n<div>\n        A function, or array of functions, that is called when the Deferred is resolved or rejected.\n      <\/div>\n<\/li>\n<li id=\"deferred-always-alwaysCallbacks-alwaysCallbacks-alwaysCallbacks\">\n<div><strong>alwaysCallbacks<\/strong><\/div>\n<div>Type: <a href=\"http:\/\/api.jquery.com\/Types\/#Function\">Function<\/a>()<\/div>\n<div>\n        Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected.\n      <\/div>\n<\/li>\n<\/ul>\n<\/li><\/ul>\n<div class=\"longdesc\" id=\"entry-longdesc\">\n    <p>The argument can be either a single function or an array of functions. When the Deferred is resolved or rejected, the <code>alwaysCallbacks<\/code> are called. Since <code>deferred.always()<\/code> returns the Deferred object, other methods of the Deferred object can be chained to this one, including additional <code>.always()<\/code> methods. When the Deferred is resolved or rejected, callbacks are executed in the order they were added, using the arguments provided to the <a href=\"\/deferred.resolve\/\"><code>resolve<\/code><\/a>, <a href=\"\/deferred.reject\/\"><code>reject<\/code><\/a>, <a href=\"\/deferred.resolveWith\/\"><code>resolveWith<\/code><\/a> or <a href=\"\/deferred.rejectWith\/\"><code>rejectWith<\/code><\/a> method calls. For more information, see the documentation for <a href=\"\/category\/deferred-object\/\">Deferred object<\/a>.<\/p>\n    <p><strong>Note:<\/strong> The <code>deferred.always()<\/code> method receives the arguments that were used to <code>.resolve()<\/code> or <code>.reject()<\/code> the <code>Deferred<\/code> object, which are often very different. For this reason, it's best to use it only for actions that do not require inspecting the arguments. In all other cases, use explicit <a href=\"\/deferred.done\/\"><code>.done()<\/code><\/a> or <a href=\"\/deferred.fail\/\"><code>.fail()<\/code><\/a> handlers since the arguments will have well-known orders.<\/p>\n  <\/div>\n<section class=\"entry-examples\" id=\"entry-examples\"><header><h2>Example:<\/h2><\/header><div class=\"entry-example\" id=\"example-0\">\n<p>Since the <a href=\"\/jQuery.get\/\"><code>jQuery.get()<\/code><\/a> method returns a <code>jqXHR<\/code> object, which is derived from a Deferred object, we can attach a callback for both success and error using the <code>deferred.always()<\/code> method.<\/p>\n<div class=\"syntaxhighlighter javascript\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t\n\t\t\t\t<td class=\"gutter\">\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n1\">1<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n2\">2<\/div>\n\t\t\t\t\t\n\t\t\t\t\t\t<div class=\"line n3\">3<\/div>\n\t\t\t\t\t\n\t\t\t\t<\/td>\n\t\t\t\t\n\t\t\t\t<td class=\"code\">\n\t\t\t\t\t<pre><div class=\"container\"><div class=\"line\"><code>$.get( <span class=\"hljs-string\">\"test.php\"<\/span> ).always(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>  alert( <span class=\"hljs-string\">\"$.get completed with success or error callback arguments\"<\/span> );<\/code><\/div><\/div><div class=\"container\"><div class=\"line\"><code>});<\/code><\/div><\/div><\/pre>\n\t\t\t\t<\/td>\n\t\t\t<\/tr>\n\t\t<\/tbody>\n\t<\/table>\n<\/div>\n\n<\/div><\/section>\n<\/div><\/article>","protected":false},"excerpt":{"rendered":"<p>Add handlers to be called when the Deferred object is either resolved or rejected.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,96],"tags":[],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-deferred-object","category-96"],"_links":{"self":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":1,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/142\/revisions"}],"predecessor-version":[{"id":143,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/posts\/142\/revisions\/143"}],"wp:attachment":[{"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/media?parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/categories?post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/api.jquery.com\/wp-json\/wp\/v2\/tags?post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}