[英]How to store specific registration form field values into sql server, when user exits the browser window or redirects to another page?
What I'm trying to achieve is, I need the email field value, and contact field value(assuming user entered values in those fields) to be stored in the sql database when the user decides not to continue with finishing the registration, and decides to either close the browser window, or redirect to another page. 我想要实现的是,当用户决定不继续完成注册并决定时,我需要将电子邮件字段值和联系字段值(假设用户在这些字段中输入的值)存储在sql数据库中关闭浏览器窗口或重定向到另一个页面。 How to achieve that ? 如何实现呢?
You need to handle either of the unload or beforeunload events (the latter if you want to try to persuade the user not to close / redirect). 您需要处理unload或beforeunload事件(如果您想说服用户不要关闭/重定向, 则为后者)。
You then need a JavaScript function to send the data back to your server, perhaps as an Ajax POST, having gathered the email and contact fields. 然后,您需要一个JavaScript函数来将数据发送回您的服务器(可能是作为Ajax POST),并已收集了电子邮件和联系方式字段。 There are plenty examples out there of POST data back to your server ( JQuery docs )... 有很多示例可以将POST数据返回到您的服务器( JQuery docs )...
In JQuery, you'd do something like: 在JQuery中,您将执行以下操作:
$(window).unload(function () {
sendMessageToServer();
});
Or in JavaScript without JQuery; 或在没有JQuery的JavaScript中;
window.onunload = sendMessageToServer;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.