且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AJAX - 当用户离开页面 - 好或坏的做法/执行?

更新时间:2023-12-01 20:14:40

在卸载执行AJAX调用不会在所有情况下工作得很好。通常,Web浏览器几乎立即关闭面板和AJAX调用可能会丢失。

Performing AJAX calls on unload does not work very well in all situations. Usually, the web browser closes the panel almost immediately and the AJAX call may be lost.

如果你想发送的分析数据,我建议将它们发送关闭页面中的事先。例如,5秒后发送,然后10秒,20秒等。使用唯一标识符找到的最新信息。间隔是由你的基础上如何precise测量需要,而不是惹恼额外带宽用户: - )

If you want to send analytical data, I suggest to send them in advance of closing the page. For example, send it after 5sec, then 10sec, 20sec, etc. Use unique identifier to find the latest information. The interval is up to you based on how precise measuring you need and not to annoy the user for additional bandwidth :-)