🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 异步请求 Hook ajax 在请求前后的所有hook 事件,注意必须为全局监听 ### ajaxPrefilter ### ajaxStart ### ajaxSend ### ajaxSuccess ### ajaxComplete ### ajaxError <details> <summary>index.html</summary> ``` <!DOCTYPE html> <html> <body> <div class="trigger">Trigger</div> <div class="result">result</div> <div class="log"></div> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $.ajaxPrefilter(function (options, originalOptions, jqXHR ) { console.log("ajaxPrefilter"); }) // 注意全局代理 $(document).ajaxStart(function() { console.log("ajaxStart"); }); $(document).ajaxSend(function() { console.log("ajaxSend "); $( ".log" ).html("ok"); }); $(document).ajaxSuccess(function() { console.log("ajaxSuccess "); }); $(document).ajaxComplete(function() { console.log("ajaxComplete "); }); $(document).ajaxError(function() { console.log("ajaxError start"); $( ".log" ).html("err"); console.log("ajaxError end"); }); $( ".trigger" ).click(function() { //异步请求 $( ".result" ).load("test.html"); }); </script> </body> </html> ``` </details> <br /> 控制台输出 ``` ajaxPrefilter ajaxStart ajaxSend ajaxSuccess ajaxComplete ```