I am trying to override the jQuery ajax function to handle a default action on a success event but also executing the callback function that i am using in the options parameter.
What the purpose is there is tags returning in the response that I always want to strip out of the response for use elsewhere.
The scenario is:
- Ajax submit
- Ajax Success
- –DEFAULT SUCCESS ACTION
- –Call Ajax Success Callback
Can anyone help?
I have tried extending
jQuery.ajaxjQuery.ajaxSuccessjQuery.ajax.done
The code I have is:
var _ajaxSuccess = jQuery.fn.ajaxSuccess;
$.fn.extend({
ajaxSuccess: function (a)
{
_ajaxSuccess.apply(this, a);
}
});
There is the global
ajaxSuccesscallback:That will let you call your own function on every successful AJAX call without interfering with the usual success callbacks.
There are various other global AJAX event handlers that you might want to look at too.
If those callbacks don’t have the right timing or capabilities for you, then you could write your own wrapper for
$.ajaxand use that:You can do whatever you need to the usual success callback parameters before calling the original success callback. You’d call
wrapped_ajaxin exactly the same way as$.ajax. You could use the same technique to hook into the other callbacks as well.