jQuery depreciated function for cross domain response-Collection of common programming errors

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(/]+?\/>|/gi, '')}, 'success'); fails with response Uncaught TypeError: Object # has no method 'isResolved'

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() http://api.jquery.com/deferred.state/ which has taken over.

Any help would be massively appreciated. Going back to a previous version of jQuery isn’t an option really.

Full function below.

jQuery.ajax = (function(_ajax){

    var protocol = location.protocol,
        hostname = location.hostname,
        exRegex = RegExp(protocol + '//' + hostname),
        YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?',
        query = 'select * from html where url="{URL}" and xpath="*"';

    function isExternal(url) {
        return !exRegex.test(url) && /:\/\//.test(url);
    }

    return function(o) {

        var url = o.url;

        if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) {

            // Manipulate options so that JSONP-x request is made to YQL

            o.url = YQL;
            o.dataType = 'json';

            o.data = {
                q: query.replace(
                    '{URL}',
                    url + (o.data ?
                        (/\?/.test(url) ? '&' : '?') + jQuery.param(o.data)
                    : '')
                ),
                format: 'xml'
            };

            // Since it's a JSONP request
            // complete === success
            if (!o.success && o.complete) {
                o.success = o.complete;
                delete o.complete;
            }

            o.success = (function(_success){
                return function(data) {
                    if (_success) {
                        // Fake XHR callback.
                        _success.call(this, {
                            responseText: data.results[0]
                                // YQL screws with s
                                // Get rid of them
                                .replace(/]+?\/>|/gi, '')
                        }, 'success');
                    }

                };
            })(o.success);

        }

        return _ajax.apply(this, arguments);

    };

})(jQuery.ajax);
  1. I had same problem as you and found a solution. Event though it’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.

    In jquery.xdomainajax.js go to line 62 and change

    if (_success) {
        // Fake XHR callback.
        _success.call(this, {
            responseText: (data.results[0] || '')
                // YQL screws with s
                // Get rid of them
                .replace(/]+?\/>|/gi, '')
        }, 'success');
    }
    

    to

    if (_success) {
        // Fake XHR callback.
        var obj = {
            responseText: (data.results[0] || '')
                // YQL screws with s
                // Get rid of them
                .replace(/]+?\/>|/gi, '')
        };  
        $.extend(obj,{
            isResolved: function() { return true; },
            done: function() { return true; }
        });
    
        _success.call(this, obj, 'success');
    }
    

Originally posted 2013-11-13 09:49:52.