【发布时间】:2012-12-24 05:18:57
【问题描述】:
我有一个需要使用摘要式身份验证来验证的表单。我仍在进行身份验证,但我已经布置了基本的 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>
【问题讨论】:
-
你的 javascript 是在 DOM 之后加载的吗(是 body 标签中的脚本)?如果没有,请将其放入
$(function() { ... your code here.. });jquery closuer(onready 函数) -
你是如何为 ajax 创建“url”的?
标签: jquery forms jquery-mobile submit