好吧,算出來。
在amplifyjs本節吸引了我的眼球
beforeSend : function(_xhr, _ajaxSettings) {
xhr = _xhr;
ajaxSettings = _ajaxSettings;
var ret = defnSettings.beforeSend ?
defnSettings.beforeSend.call(this, ampXHR, ajaxSettings) : true;
return ret && amplify.publish("request.before.ajax",
defnSettings, settings, ajaxSettings, ampXHR);
}
});
需要注意的是,它會調用beforeSend如果指定了它,否則設置var ret
如果設置爲true,設置爲true
,它會發布"request.before.ajax"
下載到文件中,放大聽此所以,如果你有一個beforeSend,如果它沒有返回true,該消息從未出版和解碼器從不打消息
amplify.subscribe("request.before.ajax", function(resource, settings, ajaxSettings, ampXHR) {
var _success = ampXHR.success,
_error = ampXHR.error,
decoder = $.isFunction(resource.decoder)
? resource.decoder
: resource.decoder in amplify.request.decoders
? amplify.request.decoders[ resource.decoder ]
: amplify.request.decoders._default;
if (!decoder) {
return;
}
function success(data, status) {
_success(data, status);
}
function error(data, status) {
_error(data, status);
}
ampXHR.success = function(data, status) {
decoder(data, status, ampXHR, success, error);
};
ampXHR.error = function(data, status) {
decoder(data, status, ampXHR, success, error);
};
});
!
解決方案?從beforeSend功能
還真
amplify.request.define("testRequest", "ajax", {
url: "/echo/json/",
dataType: 'json',
type: 'POST',
decoder: function(data, status, xhr, success, error) {
console.log('decoder fired');
$('.messages').append('<div>decoder fired </div>');
success(data);
},
beforeSend: function(xhr){
//not doing anything here, just logging;
console.log('before send fired');
$('.messages').append('<div>before send fired </div>');
return true; //this is the key
}
});
的作品就像一個魅力!希望這可以幫助別人試圖解決這個問題!
這確實幫了我,謝謝。在我的情況下,我試圖定義一個自定義的緩存,遇到了同樣的問題。找不到任何文檔覆蓋此。讚賞您的張貼您的研究! – Soulriser