Ajax Tracking + Resend exactily same Ajax Request

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:
  1. w.$.orgajax = w.$.ajax;
  2. w.$.ajax = function(url, options) {
  3.       return $.orgajax.call($, url, options);
  4. }
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:
  1. (function($, w){
  2. w.event_history = [];
  3. w.$.orgajax = w.$.ajax;
  4. w.$.ajax = function(url, options) {
  5. var jqXHR = $.orgajax.call(this, url options);
  6. var i = w.event_history.length;
  7. w.event_history[i] = {done: [], fail: [], always: []};
  8. jqXHR._done = jqXHR.done;
  9. jqXHR.done = function(fn) {
  10. w.event_history[i]["done"].push(fn);
  11. return jqXHR._done(fn);
  12. }
  13. jqXHR._fail = jqXHR.fail;
  14. jqXHR.fail = function(fn) {
  15. w.event_history[i]["fail"].push(fn);
  16. return jqXHR._fail(fn);
  17. }
  18. jqXHR._always = jqXHR.always;
  19. jqXHR.always = function(fn) {
  20. w.event_history[i]["always"].push(fn);
  21. return jqXHR._always(fn);
  22. }
  23. return jqXHR;
  24. }
  25. })(jQuery, window);