2012-03-31 6 views
0

Grundsätzlich habe ich diese Funktion unter Verwendung von Cross-Domain-JSONP zu erreichen, aber ein Teil der Funktion _success.call(this, { responseText: data.results[0].replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')}, 'success'); mit Antwort Uncaught TypeError: Object #<Object> has no method 'isResolved'jQuery veraltete Funktion für Cross-Domain-Antwort

Jetzt weiß nicht ich .isResolved()http://api.jquery.com/deferred.isResolved/ veraltete und so war ich frage mich, wie kann ich gehen Sie es mit deffered.state()http://api.jquery.com/deferred.state/ arbeiten, die übernommen hat.

Jede Hilfe würde massiv geschätzt werden. Zurück zu einer früheren Version von jQuery ist keine Option wirklich.

Volle Funktion unten.

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 <script>s 
           // Get rid of them 
           .replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '') 
         }, 'success'); 
        } 

       }; 
      })(o.success); 

     } 

     return _ajax.apply(this, arguments); 

    }; 

})(jQuery.ajax); 

Antwort

3

Ich hatte das gleiche Problem wie Sie und fand eine Lösung. Event, obwohl es noch nicht her ist, seit die Fragen gestellt wurden, entschied ich mich, meine Lösung zu posten, wenn jemand anders diese Frage beantworten sollte.

In jquery.xdomainajax.js gehen 62 auszukleiden und

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

zu

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

    _success.call(this, obj, 'success'); 
} 
+0

Dank Mann zu ändern. Zu spät, um diese Zeit zu nutzen, aber hoffentlich finden die Leute das nützlich. Prost wieder –

+0

löste mein Problem, danke Mann! – Miru

Verwandte Themen