<!-- 查詢student_id是否存在 -->
<select id="getStudent_id" resultMap="studentMap" parameterType="int">
SELECT * from student where student_id = #{student_id}
</select>@RequestMapping("/studentID")
public Student getStudent_id(Integer student_id) {
Student student = userService.getStudent_id(student_id);
if (student==null){
System.out.println("沒有");
}else{
System.out.println("有");
}
return student;
}function check() {//js表單驗(yàn)證方法
var text = document.getElementById("xh").value;//通過id獲取需要驗(yàn)證的表單元素的值
if (text == "") {
alert("請(qǐng)輸入學(xué)號(hào)!");//彈出提示
return false;//返回false(不提交表單)
}
if (!(/(^[1-9]\d*$)/.test(text))) {
alert("請(qǐng)輸入學(xué)號(hào)!");//彈出提示
return false;//返回false(不提交表單)
}
var student_id=$("#student_id").val();
$.ajax({
url:"<%=basePath%>user/studentID",
type:"post",
data:{"student_id":student_id},
dataType:"json",
success:function(data){
if (data!=null ) {
alert("有");
}else if(data==null && username !=''){
alert("沒有");
}
xmlhttp.open("GET","getcustomer.asp?q="+str,true);
xmlhttp.send();
//alert("啊啊啊");
}
});
return true;//提交表單
}
</script>
<body>
<div class="listDIV">
<table 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="根據(jù)學(xué)號(hào)查詢">
<button class="glyphicon glyphicon-select" onclick="return check();">查詢</button>
</form>我用ssm做的增刪改查,搜索我想先校驗(yàn)一下數(shù)據(jù)庫數(shù)據(jù)是否存在,存在就直接跳轉(zhuǎn)查詢,不存在就彈窗提示,中止提交表單,JS代碼是我粘過來的,不會(huì)JS,有錯(cuò)誤希望能告訴我如何改正,謝謝
ajax校驗(yàn)數(shù)據(jù)庫數(shù)據(jù)是否存在
慕工程0101907
2019-04-24 18:19:15