显示加载程序直到所有ajax asyc调用未完成 [英] Show loader till all ajax asyc calls is not finished

查看:152
本文介绍了显示加载程序直到所有ajax asyc调用未完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果有任何解决方案,请澄清以下问题 -

在ASP.NET中,我使用带有async =的$ .ajax并行调用4个Web方法真正。现在让我们假设有4个函数我打电话来利用ajax的好处 -



BindGridRecords();

BindNotifications() ;

BindProjectFiles();

BindFileCount();



所有这些都按照与如上所述。我使用了一个加载器gif图像在一个div中以全屏显示加载器并调用第一个函数来显示它并隐藏在最后一个函数中(我知道它不是一个好方法,因为它可能是最后一个函数可能在异步调用中的第一个之前完成)。现在我没有办法如何在所有上述调用都没有完成之前显示加载器图像。首先完成哪一个并不重要。



我尝试了什么:



我曾尝试使用$ .when()函数,但看起来它同步调用并降低了性能。因此,没有使用异步调用的目的。



现在我使用async = false并以另一个启动的方式设置函数完成早期之后。但这需要时间。



i也试过这个,但它不能很好地工作,因为它也会影响其他电话



Hi,
Please clarify following problem if any solution is there -
In ASP.NET i am calling 4 Web Methods in parallel using $.ajax with async=true. Now lets assume there are 4 functions that i am calling to utilize the benefit of ajax as -

BindGridRecords();
BindNotifications();
BindProjectFiles();
BindFileCount();

All of them are called in same sequence as describe above. I had used a loader gif image to show the loader in full screen in a div and called in first function to show it and hide in the very last function (I know that it is not a good way because it may be possible that the last function may completed before the first one in async calls). Now i do not have any way how to show the loader image until all of the above calls have not completed. It doesn't matter which one completed first.

What I have tried:

I had tried the $.when() function but it looks like it calls in synchronous and degrade the performance. So the purpose of async calls is not utilized.

For now i am using async=false and set the functions in a way that the other one starts after complete the early one. But it is taking time.

i had also tried this as well, but it does not works perfectly because it affects the other calls as well

$(document).ajaxStart(function() {
    $('#overlay').show();    
});

$(document).ajaxStop(function() {
    $('#overlay').hide();
});

推荐答案

.ajax async = true。现在让我们假设有4个函数我打电话来利用ajax的好处 -



BindGridRecords();

BindNotifications() ;

BindProjectFiles();

BindFileCount();



所有这些都按照与如上所述。我使用了一个加载器gif图像在一个div中以全屏显示加载器并调用第一个函数来显示它并隐藏在最后一个函数中(我知道它不是一个好方法,因为它可能是最后一个函数可能在异步调用中的第一个之前完成)。现在我没有办法如何在所有上述调用都没有完成之前显示加载器图像。首先完成哪一个并不重要。



我尝试了什么:



我曾尝试过
.ajax with async=true. Now lets assume there are 4 functions that i am calling to utilize the benefit of ajax as -

BindGridRecords();
BindNotifications();
BindProjectFiles();
BindFileCount();

All of them are called in same sequence as describe above. I had used a loader gif image to show the loader in full screen in a div and called in first function to show it and hide in the very last function (I know that it is not a good way because it may be possible that the last function may completed before the first one in async calls). Now i do not have any way how to show the loader image until all of the above calls have not completed. It doesn't matter which one completed first.

What I have tried:

I had tried the


.when()函数,但看起来它同步调用并降低了性能。因此,没有使用异步调用的目的。



现在我使用async = false并以另一个启动的方式设置函数完成早期之后。但这需要时间。



i也试过这个,但它不能很好地工作,因为它也会影响其他电话



.when() function but it looks like it calls in synchronous and degrade the performance. So the purpose of async calls is not utilized.

For now i am using async=false and set the functions in a way that the other one starts after complete the early one. But it is taking time.

i had also tried this as well, but it does not works perfectly because it affects the other calls as well


(document).ajaxStart(function(){
(document).ajaxStart(function() {


这篇关于显示加载程序直到所有ajax asyc调用未完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆