我在全局范围内拥有这部分代码以在我的页面中显示加载面板。
$(document)
.ajaxStart(function () {
$('#loadingPanel').fadeIn();
})
.ajaxStop(function () {
$('#loadingPanel').fadeOut();
});
因此,只要我像这样调用 ajax 操作,它就会自动显示加载面板:
$.ajax({
type: "GET",
url: "localhost:8080/api/data/Test/GetData",
success: doSomething
});
但只是在特定情况下,我想避免显示加载面板。有没有办法调用
$('#loadingPanel').hide();
在此代码 .ajax 操作中,或者有一种变通方法可以避免仅针对某些 ajax 操作加载面板,而不是调用每个 ajax 操作的 fadeIn 和 fadeOut。
最佳答案
当调用$.ajax(options)
时,你可以在options中设置global: false
来防止.ajaxStart()
免于被触发。
global
Whether to trigger global Ajax event handlers for this request. The default istrue
. Set tofalse
to prevent the global handlers likeajaxStart
orajaxStop
from being triggered. This can be used to control various Ajax Events.
关于javascript - 启动 Ajax 操作时停止或隐藏加载面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38620380/