jquery - How to enable remember password in case of AJAX login? -
i have web app have simple login box. there no form submit , login procedure implemented via jquery ajax.
in such scenario, how can make web browser display "do want browser remember password?" dialog?
thanks in advance!
note: i'm looking solution works @ least in recent version of major browsers.
edit: use cookies remembering user login. problem browsers don't offer remember password.
here html:
<div class="window loginwindow sn-login"> <div> <input type="text" id="username" placeholder='username' /> </div> <div> <input type="password" id="password" placeholder='password' /> </div> <div> <div> <input type="checkbox" id="rememberme" /> <label for="rememberme">remember login</label> </div> <div> <button class="loginsubmit">login</button> </div> </div> </div>
here javascript:
var $username = $("#username"), $rememberme = $("#rememberme"), $password = $("#password"); var name = $username.val(), pw = $password.val(); $.ajax({ type: "post", url: "/useractions/login", datatype: "json", data: { password: pw, email: name }, success: function (data) { if (data.success) { if ($rememberme.is(":checked")) { // omitted brevity } window.location.reload(); } else { // omitted brevity } } });
just create form element wrapper controls , use form's submit handler perform ajax call doing.
<form id="myform"> <div class="window loginwindow sn-login"> <div> <input type="text" id="username" placeholder='username' /> </div> <div> <input type="password" id="password" placeholder='password' /> </div> <div> <div> <input type="checkbox" id="rememberme" /> <label for="rememberme">remember login</label> </div> <div> <button class="loginsubmit">login</button> </div> </div> </div> </form>
change script this:
$('.loginsubmit').on('click', function(){ $("#myform").submit(function(){ var $username = $("#username"), $rememberme = $("#rememberme"), $password = $("#password"); var name = $username.val(), pw = $password.val(); $.ajax({ type: "post", url: "/useractions/login", datatype: "json", data: { password: pw, email: name }, success: function (data) { if (data.success) { if ($rememberme.is(":checked")) { // omitted brevity } window.location.reload(); } else { // omitted brevity } } }); return false; }); });
Comments
Post a Comment