simultaneous page load and ajax call

◇◆丶佛笑我妖孽 提交于 2019-12-12 04:26:50

问题


I have a web application with some pages take quite a long time to load because of what they have to do in code behind. I would like to show what is going on to the user by showing the different status of the process.

I was thinking about calling recursively (by ajax) a page which ready a value in the session. This value is set by the page that take time to load. The problem is that the page called by ajax is not executed while the other page load is finished. Is there some way to do that?

Thanks advance


回答1:


The usual pattern here is to load an initial status page that triggers an AJAX call to retrieve the final version of the page, overwriting the original with the result of your AJAX call when it completes.




回答2:


Separate the part of the code that takes a long time and call it asynchronously (e.g. as a WebMethod) on page load, e.g. if using jQuery, on document.ready. You could also fake this using an UpdatePanel which is set to conditional refresh, and the code is never run by default. Then refresh it from script using __doPostBack('updatePanelUniqueID','').



来源:https://stackoverflow.com/questions/6216787/simultaneous-page-load-and-ajax-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!