I have made a custom sort of wrapper for the JQuery’s Ajax function and everything is working quite nicely but now I want to go a bit further. I want to add a custom bit of code to the Success function that will be automatically called with each Ajax Request but that won’t overwrite what is specified in the actual request. It needs to be called in the success since it will be modifying content received from the server.
My custom Ajax Func:
$.adv_ajax = function(options) {
if (!(options.url)){
options.url="index.php";
}
if (!(options.data_type)){
options.dataType='json';
}
var extra_success=function(){
add_special_fx();
}
options.success=options.success+extra_success;
return $.ajax(options);
}
A typical Ajax call using it:
$.adv_ajax({
url: "user_accounts.php",
dataType: 'json',
success: function(response){
$("#mydiv").html(response);
}
});
If you need to call custom function only in your wrapper, wrap calling your handler to the another function where you can call as many functions as you need:
The only thing that I not sure that it will work if your reassing
options.successwith new function, maybe you will need to create separateoptionsobject end extedn it with current one.