我有一个需要使用摘要身份验证验证的表单。我仍在进行身份验证,但我已经布置了基本的 HTML 表单。
<form method="post" id="loginForm" class="validate">
<div data-role="fieldcontain">
<label for="password">Email:</label>
<input class="required email" type="text" name="username" id="username" placeholder="username@target.com">
</div>
<div data-role="fieldcontain">
<label for="password">Password:</label>
<input class="required" type="password" name="password" id="password" placeholder="password">
</div>
<input type="submit" value="Login">
</form>
我还有一个名为 digest_auth.js 的外部 js 文件,方法是
$('#loginForm').submit(function() {
alert('click');
username = $('#username').value();
password = $('#password').value();
realm = tokens['realm'];
nonce = tokens['nonce'];
qop = tokens['qop'];
alert('submitted');
ha1 = bcrypt(username + ":" + realm + ":" + password);
ha2 = bcrypt("GET:" + "http://localhost:8090/web/login");
response = bcrypt(ha1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" ha2);
$.ajax(
type: 'GET', // maybe POST?
url: url,
complete: function(xhr, status) {
if (status == 200) {
// success. save the nonce and nc in the local storage.
// whenever you send a request to the server, use the nonce
// and nc
alert('Success');
}
else {
// failure, try again
alert('Failure');
}
}
)
});
但是, .submit 没有被调用。我在开头添加了 alert() 但我什么也没得到。我确实使用链接外部
<script type="text/javascript" src="digest_auth.js"></script>