简体   繁体   English

当用户退出浏览器窗口或重定向到另一个页面时,如何将特定的注册表单字段值存储到sql服务器中?

[英]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). 您需要处理unloadbeforeunload事件(如果您想说服用户不要关闭/重定向, 则为后者)。

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.

相关问题 当用户导航离开页面或退出浏览器时,如何在ASP.net中销毁会话 - How to destroy session in ASP.net when user navigates away from the page or exits the browser 如何存储哪个用户访问了 SQL Server 中的哪个页面 - How to store which user accessed which page in SQL Server 用户关闭浏览器或访问其他页面时如何执行方法? - How to execute a Method when a User close the Browser or visit another Page? 如何保持从主程序重新启动Windows窗体,直到另一个窗口窗体退出应用程序? - How to keep re-launching a windows form from the main program until another window form exits the application? 如何将 WPF 用户注册输入保存到我的 SQL Server 表? - How to save a WPF User registration Input to my SQL Server table? 用户退出后如何保存表单? - How to Save Form after User Exits? 检测用户何时退出浏览器或选项卡并插入数据库 - Detect when user exits the browser or tab and insert into database 当用户退出Silverlight应用程序中的浏览器时收到通知 - Getting notified when user exits browser in Silverlight application 用户 ID 不会自动增加到数据库中,并且不会在 registration_form.aspx 页面的用户 ID 字段中检索下一个用户 ID - User ID is not increasing automatically into the DB and aren't retrieving the next user id in the User ID field in registration_form.aspx page 如何在SQL Server中存储网页内容 - How to store web page content in sql server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM