Created
February 18, 2014 00:28
-
-
Save jokeyrhyme/9062125 to your computer and use it in GitHub Desktop.
override jQuery.ajax to auto-trim responseText
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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