How do I display a spinning "busy" indicator at a specific point in a web page?
I want to start/stop the indicator when an Ajax request commences/completes.
这真的只是一个显示/隐藏动画gif的问题,还是有更优雅的解决方案?
How do I display a spinning "busy" indicator at a specific point in a web page?
I want to start/stop the indicator when an Ajax request commences/completes.
这真的只是一个显示/隐藏动画gif的问题,还是有更优雅的解决方案?
您可以只显示/隐藏gif,但也可以将其嵌入ajaxSetup,因此每次ajax请求都会调用gif.
$.ajaxSetup({
beforeSend:function(){
// show gif here, eg:
$("#loading").show();
},
complete:function(){
// hide gif here, eg:
$("#loading").hide();
}
});
One note is that if you want to do an specific ajax request without having the loading spinner, you can do it like this:
$.ajax({
global: false,
// stuff
});
That way the previous $.ajaxSetup we did will not affect the request with global: false
.