我的网站有一个基于 ajax 的登录表单,并且注意到浏览器无法将其识别为登录表单,并且不会记住它的密码以方便用户登录。
当按下提交按钮时,值会发送到服务器端进行检查,然后发回响应。如果检查通过,则会设置 session ,并且页面会执行 javascript 重定向到成员(member)区域。 html 非常简单,可能是问题的原因。
HTML:
<input type='text' class='email'>
<input type='password' class='password'>
<a class='submitBtn'>SUBMIT</a>
谢谢大家!
最佳答案
我想我会用另一种方式来做。
使用表单提交到隐藏的iframe,因此窗口将像ajax post一样运行(不刷新窗口)并且密码记住功能将起作用
喜欢
<form method="post" id="" action="checkDetail.php" target="myIframe">
<input type='text' class='email'>
<input type='password' class='password'>
<input type="submit" name="" value="" id="Submit"/>
</form>
<iframe name="myIframe" id="myIframe"></iframe>
通过这种方式,您必须更改一点响应代码才能注意到 iframe 父级提交结果。
更新
它将由浏览器自动完成。如果表单指定了 'target' 属性,并且有一个 iframe 的 name 属性与表单的 target 属性完全相同,则表单操作将提交到 iframe。
因此,当您的请求成功时,您的响应将出现在 iframe 内容中。在响应中尝试这样的代码。
<?php
//php checks database here
?>
<script>
parent.formSuccess({
//your response infomation
});
</script>
并在外层页面定义一个formSuccess方法来处理提交回调
关于javascript - 使用浏览器密码记住功能的 Ajax 登录表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6532757/