{"id":439,"date":"2022-08-30T15:01:22","date_gmt":"2022-08-30T15:01:22","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/jquery-1-5-why-is-deferred-object-calling-done-in-unresolved-state-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:01:22","modified_gmt":"2022-08-30T15:01:22","slug":"jquery-1-5-why-is-deferred-object-calling-done-in-unresolved-state-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/jquery-1-5-why-is-deferred-object-calling-done-in-unresolved-state-collection-of-common-programming-errors\/","title":{"rendered":"jQuery 1.5: Why is Deferred object calling .done() in UNRESOLVED state?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;ve created a test page that mimics the problem I am getting on my actual page.<\/p>\n<p>As you can see in <code>doSomething2()<\/code>, the dfd object is deliberately never resolved. However, when I run the following code, the <code>.done()<\/code> in <code>doSomething()<\/code> always fires. Inspecting the console, you will see that <code>dfd.isResolved()<\/code> is <em>false<\/em> right before <code>.done()<\/code> runs.<\/p>\n<p>Any insights? Any help is appreciated<\/p>\n<pre><code> \n \n\n    Testing Page\n    \n\n\n    \n            \n            \n    \n\n    \n        function doSomething() {\n            $('#test div').each(function(){\n                $(this).append($('').load('http:\/\/www.google.com',function(){\n                    doSomething2().done(console.log('dosomething2 is complete'));   \n                }))\n            });\n        }\n\n        function doSomething2() {\n            var dfd = $.Deferred();\n            console.log(dfd.isResolved());\n            return dfd;\n        }\n\n        $(document).ready(function() {\n          doSomething();\n        });\n    \n\n\n<\/code><\/pre>\n<p>edit: I UNDERSTAND that this function accomplishes nothing. I&#8217;ve just made an example to replicate my problem. I UNDERSTAND that fetching &#8216;google.com&#8217; is against SOP. I&#8217;ve just created this example to replicate my problem. I am developing a web app that is meant to run locally from one html file. In this case, SOP is not strictly adhered to, so this should be ok to at least test.<\/p>\n<p><strong>edit:I&#8217;ve created a jsfiddle to test this behavior:<\/strong> http:\/\/jsfiddle.net\/Sgwpv\/2\/<\/p>\n<ol>\n<li>\n<p>Your problem is this passing in a statement to .done rather then a function<\/p>\n<p>see live example<\/p>\n<p>Internally, <code>.done<\/code> takes a list of functions and pushes them to a callback array so<\/p>\n<p><code>callbacks.push(elem);<\/code><\/p>\n<p>You pass in a statement as <code>elem<\/code> and get<\/p>\n<p><code>callbacks.push(alert(\"foo\"));<\/code><\/p>\n<p>Your pushing the return value of the statement (in this case <code>undefined<\/code>) to the callback array rather then a function.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 19:42:46. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve created a test page that mimics the problem I am getting on my actual page. As you can see in doSomething2(), the dfd object is deliberately never resolved. However, when I run the following code, the .done() in doSomething() always fires. Inspecting the console, you will see that dfd.isResolved() is false right before .done() [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-439","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=439"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/439\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}