简体   繁体   English

页面上的JavaScript保存表单卸载

[英]JavaScript save form on page unload

I'm trying to automatically save a form when leaving a page with JavaScript by using the following code 我尝试使用以下代码在使用JavaScript离开页面时自动保存表单

$(window).unload( function() {
    $("#registration-patient-form").submit();
});

Yet, somehow the form does not get submitted and I'm simply redirected to the page I'm navigating to. 但是,不知何故表单没有提交,我只是被重定向到了我要浏览的页面。 Any idea on how to accomplish this? 关于如何做到这一点的任何想法?

You should do it every x seconds. 您应该每x秒执行一次。 Because user can close the page at unexpected time. 因为用户可以在意外的时间关闭页面。 1) Create a function and call it every 1 second. 1)创建一个函数,并每1秒钟调用一次。 2) Check the data if it is changed. 2)检查数据是否已更改。 3) If data is changed, submit 3)如果数据已更改,请提交

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM