问题描述
我只是读http://stackoverflow.com/questions/1619930/how-to-check-users-leave-a-page早期的时候,突然我想,当用户离开分析数据发送回服务器的页面进行AJAX对。
I was just reading http://stackoverflow.com/questions/1619930/how-to-check-users-leave-a-page earlier on when suddenly I thought of performing AJAX when user leaves the page to send analytical data back to the server.
时对 onunload
事件进行AJAX是好还是坏的做法/执行?
Is performing AJAX on the onunload
event a good or bad practice/implementation?
推荐答案
在卸载执行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 :-)
这篇关于AJAX - 当用户离开页面 - 好或坏的做法/执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!