Ajax提交用户名密码模板,合法即可提交非法不能提交

<form id="form1" action="${basePath}/people/user/save.do" align="center" method="post">
	用户名:<input type="text" name="userName" /><br/> 
	密&nbsp;码:<input type="password" name="userPassword" /><br/>
	<input type="button" value="注册" />
</form>
$(function() {
	//点击提交按钮之后提交ajax验证,正确表单正常提交,错误表单不能提交
	$("input[type=button]").click(function() {
		var inputObject = $(this);
		$.ajax({
			//发送的方式及地址等
			type: "POST",
			dataType: "json",
			url: "/1/register.do",
			data: "peopleName=" + $("input[name=userName]").val() + "&PeoplePassword=" + $("input[name=userPassword]").val(),
			//验证中
			beforeSend: function(x) {
				inputObject.next().html("验证中....");
			},
			//接受返回数据
			success: function(msg) {
				//如果用户名密码不合法,提交按钮失效,弹出错误信息
				if (msg.result == false) {
					alert(msg.resultMsg);
				} else {
					$("#form1").submit();
				}
			}
		});
	});
})

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注