问题
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