jQuery Core, Bug #4825
http://bugs.jquery.com/ticket/4825
by James Greene
HTML
<h3>`complete` handler of `$.ajax` doesn't receive the data modified by `dataFilter`</h3>
<ul id="dump">
</ul>
CSS
.problem {
color: red;
font-weight: bold;
}
JavaScript
var show = (function() {
var $el = $('#dump');
var stringify = function(o) {
if (typeof o !== 'undefined') {
return JSON.stringify(o);
}
else {
return '<span class="problem">' + JSON.stringify(o) + '</span>';
}
};
return function(name, obj) {
$el.append('<li>' + name + ': <ul>' +
Object.keys(obj).map(function(key) {
return '<li>' + key + ': ' + stringify(obj[key]) + '</li>';
}).join('') +
'</ul></li>'
);
};
})();
var succeeded = null;
var deferred = $.ajax({
type: 'post',
url: '/echo/html/',
contentType: 'text/html',
dataType: 'html',
data: {
html: "ECHO!",
delay: 2
},
dataFilter: function(data, type) {
var returnData = "^^SILENCE^^";
show('dataFilter', {
data: data,
type: type,
returnData: returnData
});
return returnData;
},
success: function(data, textStatus, jqXHR) {
succeeded = true;
show('success', {
data: data,
textStatus: textStatus,
jqXHR: jqXHR
});
},
error: function(jqXHR, textStatus, errorThrown) {
succeeded = false;
show('error', {
jqXHR: jqXHR,
textStatus: textStatus,
errorThrown: errorThrown
});
},
complete: function(jqXHR, textStatus, emptyArg) {
show('complete', {
jqXHR: jqXHR,
textStatus: textStatus,
emptyArg: emptyArg
});
}
})
.done(function(data, textStatus, jqXHR) {
succeeded = true;
show('done', {
data: data,
textStatus: textStatus,
jqXHR: jqXHR
});
})
.fail(function(jqXHR, textStatus, errorThrown) {
succeeded = false;
show('fail', {
jqXHR: jqXHR,
textStatus: textStatus,
errorThrown:...