Jquery 在等待post响应时添加正在加载的图像
我想在jquery中添加加载图像或更改鼠标光标,同时等待帖子的响应 jqueryJquery 在等待post响应时添加正在加载的图像,jquery,Jquery,我想在jquery中添加加载图像或更改鼠标光标,同时等待帖子的响应 jquery $.post(url,data, function(response){ //add a loading cursor to indicate that it is waiting for a response? alert(response); }); 我需要这个,因为响应需要很长时间才能弹出 有什么想法吗?谢谢在ajax调用之前更改光标,然后在成功处理程序中重新更改: $('body'
$.post(url,data,
function(response){
//add a loading cursor to indicate that it is waiting for a response?
alert(response);
});
我需要这个,因为响应需要很长时间才能弹出
有什么想法吗?谢谢在ajax调用之前更改光标,然后在成功处理程序中重新更改:
$('body').css('cursor','wait');
$.post(url,data, function(response){
$('body').css('cursor','default');
});
如果使用$.ajax,您还有几个选项:
$.ajax({
url : url,
data: data,
type: 'POST',
beforeSend: function() {
$('body').css('cursor','wait');
}
}).done(function(data) {
// do something with data
}).fail(function() {
console.log('error');
}).always(function() {
$('body').css('cursor','default');
});
同样的逻辑也适用于正在加载的图像或您决定添加的任何内容?这里有一个使用$.ajax()的选项。您需要在DOM中定义隐藏的loadingImage
$.ajax({
type:'POST',
...
beforeSend:function(){
$('.loadingImg').show();
},
complete:function(){
$('.loadingImg').hide();
},
...
});