简体   繁体   English

使用AJAX提取并加载整个页面

[英]Fetch and load a whole page with AJAX

I realize that it's generally not a good idea to do this but the reason why I want to is because it's a really heavy page and I want to show the user progress of the download and when it's done load the page. 我意识到这样做通常不是一个好主意,但是我想要这样做的原因是因为它是一个非常繁琐的页面,并且我想向用户展示下载的进度以及完成下载页面的时间。 I can either do this with some kind of spinner but is it possible for me to show the actual progress? 我可以使用某种微调器来执行此操作,但是我可以显示实际进度吗? Can I see how much and what data has been downloaded? 我可以查看下载了多少数据吗? Let's say I use jQuery for the AJAX-request how do I do this? 假设我将jQuery用于AJAX请求,该怎么做? If you have other suggestions please feel free to suggest. 如果您还有其他建议,请随时提出建议。

Perhaps if its possible to divide the page into several pieces that you load, you could show some progress using javascript. 也许如果可以将页面分成几部分进行加载,则可以使用javascript来显示一些进度。 But I don't think it's possible to count the number of bytes loaded from one go 但是我认为不可能一口气加载字节数

You can't monitor the progress using javascript only. 您不能仅使用javascript监视进度。 You will need to have a server component as well. 您还将需要具有服务器组件。 An Ajax request will only trigger a callback when it is completed. Ajax请求仅在完成时才触发回调。 So, you will need to poll the server with a second Ajax request to ask how many bytes have already been sent. 因此,您将需要使用第二个Ajax请求来轮询服务器,以询问已经发送了多少个字节。 Your server must be able to monitor the progress of an "upload". 您的服务器必须能够监视“上载”的进度。

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

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