简体   繁体   中英

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. 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).

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. There are plenty examples out there of POST data back to your server ( JQuery docs )...

In JQuery, you'd do something like:

$(window).unload(function () {
    sendMessageToServer();
});

Or in JavaScript without JQuery;

window.onunload = sendMessageToServer;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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