在页面重新加载时正在进行的Ajax请求会发生什么 [英] What happens with in progress Ajax request on page reload

查看:192
本文介绍了在页面重新加载时正在进行的Ajax请求会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有报告页面,用户可以从中导出CSV格式的报告。在 C#MVC 中的服务器上,我们创建 MemoryStream 并在数据转换后写入每一行,最后以<$ c发送响应$ C>文件。完成请求后,浏览器会自动下载此文件。由于报告需要很长时间才能生成,因此用户必须在阻塞状态下等待它。

要解决此问题,我将发送异步Ajax请求和通过创建 Blob URL 将响应保存为 CSV文件

此工作正常如果用户停留在报告页面上,直到所有报告都被下载,但如果用户从报告页面导航到其他页面 Ajax请求响应迷路。

所以我有一些以下问题

We have report page from where user can export the reports in CSV. At server in C# MVC we create MemoryStream and write each row after data transformation and finally send response as a File. Browser automatically downloads this files once request complete. As reports takes long time to get generated, user has to wait for it in blocking state.
To tackle this I am sending the Async Ajax request and saving the response as CSV file by creating Blob URL.
This works fine If user stay on report page until all the reports gets downloaded but if the user navigate from report page to other page Ajax request response get lost.
So I have some below questions


  1. 正在进行的操作 Ajax请求页面重新加载

  2. 页面重新加载取消请求已在服务器上启动并正在进行中

  3. 如果浏览器已重新加载页面,服务器响应会发生什么情况

  4. 有没有办法在重新加载之后保持这样的请求,这需要进一步

  1. What happens with in progress Ajax request on page reload
  2. Does page reload cancel request which was initiated and in progress on the server
  3. What happens with the server response if browser already reloaded page
  4. Is there any way to keep alive such request after reload which needed further


推荐答案


  1. 服务器将在用户导航时继续编译报告离开了。

  1. The server will continue to compile the report while the user navigates away.

没有。

无处可去。浏览器有一个新页面,没有待处理的请求;它不知道任何先前的活动(HTML是无状态的)。

It has nowhere to land. The browser has a 'new' page with no pending requests; it has no knowledge of any prior activity (HTML is stateless).

没有。也许您可以使用onBeforeUnload事件处理程序来警告用户并允许他们留在页面上。但有些浏览器会忽略该事件的任何事件处理程序,因此很难使其可靠。

No. Perhaps you could rig an onBeforeUnload event handler that would warn the user and allow them to stay on the page. But some browsers ignore any event handlers on that event, so it would be hard to make it reliable.

你最好的赌注可能是界面变化。在浏览页面上发布通知将取消他们正在等待的任何报告。并为用户提供一种简单的方法来了解他们的报告正在准备中,例如html加载gif。

Your best bet is probably an interface change. Put a notice on the page that navigating away will cancel any reports they're waiting for. And give the users an easy way to know their report is being prepared, like an html loading gif.

这篇关于在页面重新加载时正在进行的Ajax请求会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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