jQuery Ajax Intercept
Allows you to respond to a success message in an ajax call to a url of "?". The call will fail, having never made a request, but your success handler will fire. Then fake the data and respond accordingly. Even works for Kendo Grids to fake server side paging.
JavaScript
console.log('sdsds')
//intercept ajax failure for url of '?' and resolve as successful
(function jQueryInteceptRejectWithAndCallResolveWith() {
jQuery._Deferred = jQuery.Deferred;
jQuery.Deferred = function (a) {
var deferred = new jQuery._Deferred(a);
deferred._rejectWith = deferred.rejectWith;
deferred.rejectWith = function (callbackContext, data, unknown) {
if (callbackContext && callbackContext.url && callbackContext.url[0] === "?") {
deferred.resolveWith(callbackContext, data || null);
}
else {
deferred._rejectWith(callbackContext, data, unknown);
}
}
return deferred;
};
}());
$.ajax("?").success(function(){alert("Yay data!")});