基本上我一直用這個功能來實現跨域JSONP但功能_success.call(this, { responseText: data.results[0].replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')}, 'success');
失敗響應的一部分Uncaught TypeError: Object #<Object> has no method 'isResolved'
jQuery的棄用功能跨域響應
現在我知道.isResolved()
http://api.jquery.com/deferred.isResolved/已經過時,所以我在想,我怎麼能去處理它已經接管的deffered.state()
http://api.jquery.com/deferred.state/。
任何幫助將大規模讚賞。回到以前的jQuery版本並不是真正的選擇。
以下全部功能。
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);
感謝的人。對於我來說這個時間太晚了,但希望人們會覺得這很有用。再次歡呼 – 2012-08-03 15:40:11
解決了我的問題,謝謝! – Miru 2014-11-03 11:27:57