我尝试在页面卸载/visibilityChange上使用ajax请求。我发现navigator.sendBeacon是最好的选择。array_data_on_unload) let result = navigator.sendBeacon(window.location.protocol+'//'+window.location.hostname+
文档表明sendBeacon通过HTTP POST request发送数据,但是在PHP中$_POST变量似乎是一个空数组。以下是我的javascript代码:navigator.sendBeacon('beacon_log.php','My lost data')发现如果我使用navigator.sendBeacon('beacon_log.php?g_data=My data ok','Still lost!'),我可以用