如何知道是否有任何Ajax请求和ajax成功 [英] How to know if there is any Ajax Request and ajax Success
问题描述
我想知道如何编码这个
//if there is any ajax request
$("#loader").css("display","block");
//on success:
$("#loader").css("display","none");
注意:
i我不打算再次编码再次在我的每个ajax请求函数中。
我想要它Genric。这样我的脚本就知道是否有任何ajax请求吗 $(#loader)。css(display,block);
以及是否有任何ajax成功做 $(#loader)。css(display,none);
Note :
i am not going to code it again and again in my each ajax request function.
i want it Genric. so that my script knows if there is any ajax request do $("#loader").css("display","block");
and if there is any ajax success do $("#loader").css("display","none");
推荐答案
您正在寻找的神奇之处是 jQuery.ajaxStart()和 jQuery.ajaxStop()。您可能还会发现 jQuery.ajaxComplete()非常有用。
The magical thing you are looking for is jQuery.ajaxStart() and jQuery.ajaxStop(). You might also find jQuery.ajaxComplete() useful.
示例:
$("#loader").ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
你应该使用 hide()
和 show()
方法,而不是更改显示
CSS属性。
You should use the hide()
and show()
methods instead of changing the display
CSS attribute.
这篇关于如何知道是否有任何Ajax请求和ajax成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!