简体   繁体   English

将ajax异步设置为false时,无法看到页面加载器图像

[英]Unable to see page loader image when ajax async is set as false

I am showing a loading image before an ajax call and hiding it when the success comes. 我正在ajax调用之前显示加载图像,并在成功到达时将其隐藏。

$('#Search').on('click', function (e) {

    $('#loaderImg').show();

    $.ajax({
        url: '',
        data: '',
        async: false,
        success: function (response) {

            ...some lines of code

            $('#loaderImg').hide();

        }  
    });
});

When the async is false the image is not shown, maybe because the UI is not updated when javascript is executing. 如果async为false,则不会显示图片,这可能是因为在执行javascript时未更新UI。

When async set as true the image is visible before it is hidden in success block. 当异步设置为true时,在隐藏成功块之前,图像是可见的。

Please suggest a way to make the image visible before the success block executes keeping the async parameter as false. 请提出一种在成功执行块之前使图像可见的方法,以保持async参数为false。

Tested in Chrome. 在Chrome中测试。

Have you tried global ajaxStart and ajaxStop events: 您是否尝试过全局ajaxStart和ajaxStop事件:

$('#loaderImg').bind('ajaxStart', function(){
      $(this).show();
 }).bind('ajaxStop', function(){
      $(this).hide();
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM