Ajax登录表单 - 浏览器不会保存密码

时间:2011-03-04 17:00:03

标签: ajax forms mootools

我有Ajax登录表单,它检查给定的凭据是否正确并重定向到另一个页面。登录表单本身是由HXR调用构建的 - 它不是在登录页面代码中构建的。

问题是我无法让浏览器提示记住密码。一旦我得到Firefox提示但由于表单是由XHR调用构建的,Firefox没有将值粘贴到表单中。

PS。登录成功时,我正在使用mootools(Form.send)和通常的window.location。 PSS。登录页面的地址始终相同。

以下代码由一个元素中的XHR加载(我正在使用MochaUI): JavaScript的:

$('loginwindow_form').set('send', {
    "url": "auth/ajax_login",
    "method": "post",
    "onRequest": function () {
        $("loginWindow_spinner").show();
    },
    "onComplete": function (response) {
        $("loginWindow_spinner").hide();
    },
    "onSuccess": function (responseText, responseXML) {
        window.location = "appinit";
    },
    "onFailure": function (xhr) {
        MUI.notification('onFailure');
    }
});

$("loginwindow_form").addEvent("submit", function (e) {
    !e || e.stop();
    $('loginwindow_form').send();
});

xHTML(注意表单没有提交按钮 - 该按钮位于其他位置并且具有onclick操作以发送具有给定ID的表单):

<iframe src="auth/blank" id="blankiframe" name="blankiframe" style="display:none"></iframe>
<form action="appinit" method="post" name="loginwindow_form" id="loginwindow_form" class="standardform" target="blankiframe">
    <input type="text" name="email" class="input text" id="loginwindow_form_email" />
    <input type="password" name="password" class="input text password" id="loginwindow_form_loginwindow_form_password" />
</form>

发送按钮(另一个是xhr加载的元素):

<button class="button" action="{sendForm: 'loginwindow_form'}">
    <div class="accept">Login</div>
</button>

2 个答案:

答案 0 :(得分:2)

你真的应该发布代码。在你的回调中做.send非常好,没关系。仍然,你需要发布你如何处理表格并首先发起提交。

它应该工作的方式是你拦截表单的submit方法 - 但如果你 - 比如说,有一个带有点击处理程序的按钮,它就不会被视为提交,所以它不会记住事情。另外,你在做event.stop还是.preventDefault

答案 1 :(得分:1)

我建议你使用传统的sumbit表单,但提交到隐藏的iframe。 (或者登录表单本身可以在iframe中)。这样你仍然可以将JS响应发送回将要执行的iframe,并且浏览器会知道它是一个登录表单。