Ajax Tracking + Resend exactily same Ajax Request
Hello!
I develope a CMS called Goma, in which I use jQuery very much. Sometimes I have an Ajax-Request, which is responded by an Confirm-Dialog and after the user clicks okay, the same Ajax-Request with just some other Attributes should be sent.
Since jQuery 1.8 and the deferred object I don't get the events for the Ajax-Request, so I can resend the request, but nothing happens cause of missing callback.
So I tried to override $.ajax:
- w.$.orgajax = w.$.ajax;
- w.$.ajax = function(url, options) {
- return $.orgajax.call($, url, options);
- }
But it always crashes with
RangeError: Maximum call stack size exceeded
in Chrome and doens't work in other Browsers too.
What's the problem there?
The full code for overriding would be:
- (function($, w){
- w.event_history = [];
- w.$.orgajax = w.$.ajax;
- w.$.ajax = function(url, options) {
- var jqXHR = $.orgajax.call(this, url options);
-
- var i = w.event_history.length;
- w.event_history[i] = {done: [], fail: [], always: []};
-
- jqXHR._done = jqXHR.done;
- jqXHR.done = function(fn) {
- w.event_history[i]["done"].push(fn);
- return jqXHR._done(fn);
- }
-
- jqXHR._fail = jqXHR.fail;
- jqXHR.fail = function(fn) {
- w.event_history[i]["fail"].push(fn);
- return jqXHR._fail(fn);
- }
-
- jqXHR._always = jqXHR.always;
- jqXHR.always = function(fn) {
- w.event_history[i]["always"].push(fn);
- return jqXHR._always(fn);
- }
-
- return jqXHR;
- }
- })(jQuery, window);