まず第一に、私の拙い英語をお詫びします...誰かが私の質問を理解して助けてくれることを願っています...
私は多くの $.post 呼び出しを使用するプロジェクトに取り組んでおり、それらすべてに同じ検証を追加して改善したいと考えています。
すべてのスクリプトを 1 つずつ変更したくないので、$.post 関数をオーバーライドして、すべてのスクリプトに同じものを同時に追加する方法はありますか? または、各 $.post で別の関数をトリガーする方法でしょうか? 何かのようなもの :
$.post.each(function(){[...]});
また
$('body').on('post', function(){[...]});
ありがとう !
編集:ついに私が望んでいたようにやった!これが私のコードです:
// 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;
});
}
})();