场景:我正在创建一个事件注册模块,其中用户将从预订日历中选择一个日期,填写一些输入字段并支付预订日期。 其中一个要求是,每个日期只能有一个预订。 这是两个人想要在同一时间预订同一日期的情况。因此,我们需要向稍后预订的用户预订预订日期为的消息。请稍后再回来。发送一个Ajax呼叫之前加载/卸载
为了达到这个目的,我在用户选择日期时在数据库中创建一个临时条目。针对该条目,我可以将消息显示给后来的其他用户。
逻辑上,该条目具有如果第一用户将被删除:
- 选择一些其它的日期。
- 关闭浏览器或从页面导航离开
所以,这将是供谁想要预订同一日期,第二用户。
问题:我可以在用户更改所选日期后删除条目。我无法实现第二个。我写了一个函数,它将删除该行并在未加载jQuery事件前调用该函数。显然,该功能不适用于jQuery。
window.onbeforeunload = function(){
deleteTempEntry(); //This sends an ajax call to delete the entry. Not working.
alert("The second alert"); // even this alert doesn't work.
// I actually intend to use confirm box to make sure to not to delete the entry if the user does not leave the page.
confirm("Your current progress will be removed. Are you sure?");
//Calling this return function shows the warning message but none of the other code works.
//return 'Are you sure you want to leave?';
};
我试过了,绑定/上/纯JS,但没有一个似乎工作。
如解释here,由于安全原因,我无法用onbeforeunload/unload事件做很多事情。 任何解决方法?
谢谢。
怎么样打开一个新窗口?然后在那里显示消息,并且弹出窗口上的卸载应该触发'deleteTempEntry()' –
因此,当用户关闭标签页/浏览器时,前端没有太多可以做的事情。所以你将不得不在后端维护一个超时功能,以便删除不完整的注册。 – MegaMind