First of all, I apologize for my poor English ... I hope someone understands my question and helps me ...
I am working on a project using many $ .post calls, and I want to improve them by adding the same check for all of them.
I donβt want to change all the scripts one by one, so is there a way to redefine the $ .post function to add the same thing to each of them at the same time? Or maybe a way to call another function on every $ .post? Sort of:
$.post.each(function(){[...]});
or
$('body').on('post', function(){[...]});
Thanks!
EDIT: Finally did it the way I wanted! Here is my code:
// Override $.post (function(){ // Store a reference to the original remove method. var originalPostMethod = jQuery.post; // Define overriding method. jQuery.post = function(data){ // Execute the original method. var callMethod = originalPostMethod.apply( this, arguments); callMethod.success(function(){ //console.log('success'); }); callMethod.error(function(){ //console.log('error'); }); callMethod.complete(function(){ //console.log('complete'); return callMethod; }); } })();
source share