Javascript 加载程序图像不会在带有ajax请求的chrome上显示
我有一个ajax请求,它在ajax发送之前显示加载程序图像,在请求成功时在ajax发送之后隐藏加载程序图像。加载器图像在Firefox上显示得非常完美,但在chrome上却没有 我的代码正在Firefox上运行 我的代码是Javascript 加载程序图像不会在带有ajax请求的chrome上显示,javascript,jquery,ajax,google-chrome,Javascript,Jquery,Ajax,Google Chrome,我有一个ajax请求,它在ajax发送之前显示加载程序图像,在请求成功时在ajax发送之后隐藏加载程序图像。加载器图像在Firefox上显示得非常完美,但在chrome上却没有 我的代码正在Firefox上运行 我的代码是 $.ajax({ method: "GET", url: "test.php", beforeSend:function(){ $(".loader-image").show(); }, success:function(data){ $(
$.ajax({
method: "GET",
url: "test.php",
beforeSend:function(){
$(".loader-image").show();
},
success:function(data){
$(".loader-image").hide();
//here i write success code
}
});
你的代码看起来不错。但我认为可能是beforeSend回调没有得到执行。作为另一种解决方案,您可以尝试以下代码:
$(".loader-image").show();
$.ajax({
method: "GET",
url: "test.php",
complete:function(data){
$(".loader-image").hide();
},
success: function(){
//write the success code here
}
});
我希望这有帮助
我也有同样的问题,我真的不知道它是怎么发生的,但它可以
在如下代码中使用一个小的延迟来修复
解决方案1
解决方案2
beforeSend值和success键之间缺少逗号。除此之外,我认为Chrome中的代码没有问题@克里斯托弗·梅耶斯:我刚刚发布了一个简化的问题代码,这是一个添加错误,我已经更新了问题。但问题仍然存在。@Rameez Rami的回答解决了这个问题。。但有人知道为什么它只在chrome上发生吗?这是chrome还是jquery错误?让我试试你的解决方案。如果有帮助,请告诉我。您可以检查应用于“loader image”类的初始css样式吗。基本上jquery显示/隐藏在显示属性上起作用。因此,检查是否通过css没有覆盖内联样式。请在开发控制台中检查。让我试试您的答案
$.ajax({
method: "GET",
url: "/",
beforeSend:function(){
$(".loader-image").show(1);
// please note i have added a delay of 1 millisecond , which runs almost same as code with no delay.
},
success:function(data){
$(".loader-image").hide();
//here i write success code
}
});
$.ajax({
method: "GET",
url: "/",
beforeSend:function(){
setTimeout(function(){
$(".loader-image").show();
}, 1);
// please note i have added a delay of 1 millisecond with js timeout function which runs almost same as code with no delay.
},
success:function(data){
$(".loader-image").hide();
//here i write success code
}
});