Skip to content

Instantly share code, notes, and snippets.

@jokeyrhyme
Created February 18, 2014 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokeyrhyme/9062125 to your computer and use it in GitHub Desktop.
Save jokeyrhyme/9062125 to your computer and use it in GitHub Desktop.
override jQuery.ajax to auto-trim responseText
(function () {
'use strict';
var oldFn;
oldFn = $.ajax;
$.ajax = function () {
var dfrd = new $.Deferred();
oldFn.apply($, arguments).then(function (data, status, xhr) {
if (!!xhr.responseText) {
data = $.trim(xhr.responseText);
xhr.responseText = data;
}
dfrd.resolve(data, status, xhr);
}).fail(function (xhr, status, error) {
if (!!xhr.responseText) {
xhr.responseText = $.trim(xhr.responseText);
}
dfrd.reject(xhr, status, error);
});
return dfrd.promise();
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment