[英]loader image does not show on chrome with an ajax request
I have an ajax request which shows a loader image before ajax send and hide the loader image after ajax when request success. 我有一个ajax请求,它在ajax发送之前显示一个加载器镜像,并在请求成功后在ajax之后隐藏加载器镜像。 loader image shows perfectly on Firefox but not on chrome.
loader图像在Firefox上完美显示但在chrome上没有显示。
My code is working on Firefox
我的代码正在使用Firefox
my code is.. 我的代码是......
$.ajax({
method: "GET",
url: "test.php",
beforeSend:function(){
$(".loader-image").show();
},
success:function(data){
$(".loader-image").hide();
//here i write success code
}
});
i hope this helps 我希望这有帮助
I had the same issue and i really don't know how it's happening, but it can be fixed using a small delay in code like follows.
我有同样的问题,我真的不知道它是如何发生的,但它可以使用如下代码中的小延迟来修复。
$.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
}
});
Your code seems ok. 你的代码似乎没问题。 but I think may be the beforeSend callback is not getting executed.
但我认为可能是beforeSend回调没有被执行。 As an other solution, can you try the folowing code:
作为另一种解决方案,您可以尝试以下代码:
$(".loader-image").show();
$.ajax({
method: "GET",
url: "test.php",
complete:function(data){
$(".loader-image").hide();
},
success: function(){
//write the success code here
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.