Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当“卸载”事件被触发时,我试图断开用户的连接!
$(window).bind('unload', function() { $.ajax({ url: "deconnexionUser.php", async: false }); });
它有效,但我不想使用“async:false”!
我该怎么办 ?
您无法在正在关闭的网页上启动异步事件,因此您需要在发送请求时阻止浏览器。
您是否有理由希望它是异步的?
如果您使用beforeunload,您将不会与关闭窗口竞争:
beforeunload
$(window).bind('beforeunload', function() { $.ajax({ url: "deconnexionUser.php" }); });