简体   繁体   English

全局覆盖ajax beforeSend

[英]override ajax beforeSend globally

so we have this ajax option beforeSend 所以我们在发送之前有这个ajax选项

$.ajax({
   beforeSend: function(){
     // to do
   }
 });


is there a way to override this globally? 有没有办法在全球范围内覆盖它?
for example, i want to insert a function on all ajax and I want to do this by creating a single function rather than going all $.ajax calls one by one. 例如,我想在所有ajax上插入一个函数,我想通过创建一个函数而不是逐个进行所有$ .ajax调用来实现。

You can check the .ajaxStart() - it's global for all AJAX calls. 您可以检查.ajaxStart() - 它是所有AJAX调用的全局。

Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. 每当要发送Ajax请求时,jQuery都会检查是否还有其他未完成的Ajax请求。 If none are in progress, jQuery triggers the ajaxStart event. 如果没有进行,jQuery会触发ajaxStart事件。 Any and all handlers that have been registered with the .ajaxStart() method are executed at this time. 已经使用.ajaxStart()方法注册的任何和所有处理程序都会在此时执行。

More info @ https://api.jquery.com/ajaxStart/ 更多信息@ https://api.jquery.com/ajaxStart/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM