jQuery.ajax или как заставить передавать первым аргументом ссылку на xhr
$.ajaxPrefilter(function (options, originalOptions, xhr){
options.dataTypes = [];
options.dataFilter = function (){
return xhr;
};
});
$.ajaxPrefilter(function (options, originalOptions, xhr){
options.dataTypes = ["xxx"];
options.dataFilter = function (result){
xhr.body = result;
return xhr;
};
});
$.ajaxSetup({
"converters": {
"* xxx": function (xhr){
if( /json/i.test(xhr.getResponseHeader("content-type") ){
// Без try catch, да-да!
xhr.body = JSON.parse(xhr.body);
}
return xhr;
}
}
});
(function ($, originalAjax){
$.ajax = function (){
var xhr = originalAjax.apply($, arguments);
$.extend(xhr, xhr.then( // заменяем методы done/fail/progress
function (){ return $.Deferred().resolve(xhr); },
function (){ return $.Deferred().reject(xhr); })
);
return xhr;
};
})(jQuery, jQuery.ajax)