最简单的显示方式"装载"使用jquery Ajax时?最简单、方式、QUOT、jquery

2023-09-10 16:31:55 作者:柠檬

我想知道,呈现出​​装载GIF到一个特定的jQuery Ajax请求的最简单的方法。

I want to know the easiest way of showing a 'loading' gif to a specific jquery ajax request.

我已经尝试过:

$(document).ajaxStart(function() {
    $('.hideOnLoad').hide();
});
$(document).ajaxStop(function() {
    $('.hideOnLoad').show();
});

但后来所有的Ajax请求将触发它。我只想要一个特定的jQuery Ajax请求触发装载过程(也许GIF将显示)。

but then ALL ajax requests will trigger it. i just want a specific jquery ajax request to trigger the loading process (maybe a gif will be shown).

我该怎么办呢?

推荐答案

beforeSend 回调,你必须表现出微调和完整你必须把它藏起来。仅供参考: ajaxStart ajaxStop 是全球性的AJAX事件,而 beforeSend 完整是本地的。

In beforeSend callback you have to show the spinner and in complete you have to hide it. Just FYI: ajaxStart and ajaxStop are global ajax events while beforeSend and complete are local.

 
精彩推荐
图片推荐