I created a form for SignIn. Since I don't want to refresh the page when the form is submitted, I used the $.post method to send data to a database and receive that.
and I have a problem that browser don't save password if they want save that because form don't be submitted in usual way, I thought maybe cookie is good way but i think it's not safe.
$.post example for login
function formsubmited(form, p, username) {
$.post("process_login.php", {username: username.value, p: p.value},
function(response) {
if(response == 'login')
{
// do something
}
}
});
HTML form Sample
<form name="form_login">
<input name="username"/>
<input type="password" name="password"/>
<input type="button" value="login" onclick="formsubmited(this.form, this.form.password, this.form.username);" />
</form>
how can store password on browser when form is submitting in this way? is there any way? or i should use cookies?
The case of the problem is that you are using input type="button"
and the browser save password don't get triggered on the above input type. Use input type="submit"
Just do one change in this line
<input type="button" value="login" onclick="formsubmited(this.form, this.form.password, this.form.username);" />
Don't use button
, use submit
So make it as below :
<input type="submit" value="login" onclick="return formsubmited(this.form, this.form.password, this.form.username);" />
and add return false
at the end of the function , so that form don't get sumbitted.