我正在为我的网站创建一个 AJAX 登录表单;但是,我遇到了一些我认为是 jQuery 中的错误。
代码示例:
<!DOCTYPE html>
<html>
<head>
<title>Log In</title>
</head>
<body>
<div class="errors"></div>
<input type="username" placeholder="username">
<input type="password" placeholder="password">
<input type="submit" value="Log In">
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script>
$('input[type=submit]').click(function(){
$(".errors").load(window.location.protocol + "//" + window.location.host + "?username=" + $("input[type=username]").val() + "&password=" + $("input[type=password]").val());
return false;
});
</script>
</html>
我知道这不是服务器端问题。的返回值$("input[type=username]").val()
是undefined
,而 的返回值$("input[type=password]").val()
是输入的值。谢谢大家!:)