{"id":1362,"date":"2022-08-30T15:15:54","date_gmt":"2022-08-30T15:15:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/13\/jquery-depreciated-function-for-cross-domain-response-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:54","modified_gmt":"2022-08-30T15:15:54","slug":"jquery-depreciated-function-for-cross-domain-response-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/jquery-depreciated-function-for-cross-domain-response-collection-of-common-programming-errors\/","title":{"rendered":"jQuery depreciated function for cross domain response-Collection of common programming errors"},"content":{"rendered":"<p>Basically I have been using this function to achieve cross domain JSONP but part of the function <code>_success.call(this, { responseText: data.results[0].replace(\/]+?\\\/&gt;|\/gi, '')}, 'success');<\/code> fails with response <code>Uncaught TypeError: Object # has no method 'isResolved'<\/code><\/p>\n<p>Now I know <code>.isResolved()<\/code> http:\/\/api.jquery.com\/deferred.isResolved\/ has depreciated so I was wondering how I could go about getting it working with <code>deffered.state()<\/code> http:\/\/api.jquery.com\/deferred.state\/ which has taken over.<\/p>\n<p>Any help would be massively appreciated. Going back to a previous version of jQuery isn&#8217;t an option really.<\/p>\n<p>Full function below.<\/p>\n<pre><code>jQuery.ajax = (function(_ajax){\n\n    var protocol = location.protocol,\n        hostname = location.hostname,\n        exRegex = RegExp(protocol + '\/\/' + hostname),\n        YQL = 'http' + (\/^https\/.test(protocol)?'s':'') + ':\/\/query.yahooapis.com\/v1\/public\/yql?callback=?',\n        query = 'select * from html where url=\"{URL}\" and xpath=\"*\"';\n\n    function isExternal(url) {\n        return !exRegex.test(url) &amp;&amp; \/:\\\/\\\/\/.test(url);\n    }\n\n    return function(o) {\n\n        var url = o.url;\n\n        if ( \/get\/i.test(o.type) &amp;&amp; !\/json\/i.test(o.dataType) &amp;&amp; isExternal(url) ) {\n\n            \/\/ Manipulate options so that JSONP-x request is made to YQL\n\n            o.url = YQL;\n            o.dataType = 'json';\n\n            o.data = {\n                q: query.replace(\n                    '{URL}',\n                    url + (o.data ?\n                        (\/\\?\/.test(url) ? '&amp;' : '?') + jQuery.param(o.data)\n                    : '')\n                ),\n                format: 'xml'\n            };\n\n            \/\/ Since it's a JSONP request\n            \/\/ complete === success\n            if (!o.success &amp;&amp; o.complete) {\n                o.success = o.complete;\n                delete o.complete;\n            }\n\n            o.success = (function(_success){\n                return function(data) {\n                    if (_success) {\n                        \/\/ Fake XHR callback.\n                        _success.call(this, {\n                            responseText: data.results[0]\n                                \/\/ YQL screws with s\n                                \/\/ Get rid of them\n                                .replace(\/]+?\\\/&gt;|\/gi, '')\n                        }, 'success');\n                    }\n\n                };\n            })(o.success);\n\n        }\n\n        return _ajax.apply(this, arguments);\n\n    };\n\n})(jQuery.ajax);\n<\/code><\/pre>\n<ol>\n<li>\n<p>I had same problem as you and found a solution. Event though it&#8217;s while ago since the questions was asked i decided to post my solution if somebody else should come across this question as i did.<\/p>\n<p>In <code>jquery.xdomainajax.js<\/code> go to line <code>62<\/code> and change<\/p>\n<pre><code>if (_success) {\n    \/\/ Fake XHR callback.\n    _success.call(this, {\n        responseText: (data.results[0] || '')\n            \/\/ YQL screws with s\n            \/\/ Get rid of them\n            .replace(\/]+?\\\/&gt;|\/gi, '')\n    }, 'success');\n}\n<\/code><\/pre>\n<p>to<\/p>\n<pre><code>if (_success) {\n    \/\/ Fake XHR callback.\n    var obj = {\n        responseText: (data.results[0] || '')\n            \/\/ YQL screws with s\n            \/\/ Get rid of them\n            .replace(\/]+?\\\/&gt;|\/gi, '')\n    };  \n    $.extend(obj,{\n        isResolved: function() { return true; },\n        done: function() { return true; }\n    });\n\n    _success.call(this, obj, 'success');\n}\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-13 09:49:52. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Basically I have been using this function to achieve cross domain JSONP but part of the function _success.call(this, { responseText: data.results[0].replace(\/]+?\\\/&gt;|\/gi, &#8221;)}, &#8216;success&#8217;); fails with response Uncaught TypeError: Object # has no method &#8216;isResolved&#8217; Now I know .isResolved() http:\/\/api.jquery.com\/deferred.isResolved\/ has depreciated so I was wondering how I could go about getting it working with deffered.state() [&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-1362","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1362","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=1362"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1362\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}