You can just show / hide a gif, but you can also embed that to ajaxSetup, so it's called on every ajax request.
$.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
.
More details available at: http://api.jquery.com/jQuery.ajaxSetup
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…