function check() {//js表单验证方法
var text = document.getElementById("xh").value;//通过id获取需要验证的表单元素的值
if (text == "") {
alert("请输入学号!");//弹出提示
return false;//返回false(不提交表单)
}
if (!(/(^[1-9]\d*$)/.test(text))) {
alert("请输入学号!");//弹出提示
return false;//返回false(不提交表单)
}
var student_id = $('input[name="student_id"]').val();
$.post("<%=basePath%>user/queryByUser",
{ student_id : student_id }).done(function(data) {
console.log(data.result);
if (data == null || data == "") {
console.log("没有");
alert("没有");
return false;
} else {
console.log("有");
}
}).fail(function() {
console.error("错误");
});
return true;//提交表单
}
</script>
<body>
<div class="listDIV">
<table id="FileTable" border="1" width="50%" height="50%"
style="text-align: center;">
<form action="<%=basePath%>user/one" method="post">
<input type="text" id="xh" name="student_id" placeholder="根据学号查询">
<button class="glyphicon glyphicon-select" onclick="return check();">查询</button>
</form>
return false并没有中止表单提交
ajax设置成同步请求