javascript - Is it practical to ajax the collected access information to the server when the web page is closed? ?
天蓬老师
天蓬老师 2017-05-19 10:25:34
0
1
535

I want to ajax the collected access information to the server when the web page is closed. Is it practical? ?
The approximate code structure is as follows:

window.onbeforeunload=function(e){    
    visit_end=new Date();
    visit_long=((visit_end.getTime()-visit_start.getTime())/1000).toFixed(1);
    //此处省略以上采集的访问信息

    ajax_visit_info(); //在关闭网页时,调用ajax函数发送到后台。
    //return confirm('你真的要关闭吗?');     //不想加上这个,看起来不友好。    
}

The question is, is it practical to use window.onbeforeunload to trigger ajax?
If the user's phone is stuck, or there is a problem with the network, will there be a high probability of missing the ajax trigger? ?

PS: I can test it with wamp.

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!