ajax学生校验学号,ajax校验数据库数据是否存在
青春有我
jsp?function check() {//js表單驗(yàn)證方法? ? ? ? var flag = true;? ? ? ? var text = document.getElementById("xh").value;? ? ? ? if (!(/(^[1-9]\d*$)/.test(text))) {//校驗(yàn)輸入是否為正整數(shù)? ? ? ? ? ? alert("請(qǐng)輸入學(xué)號(hào)!");? ? ? ? ? ? flag = false;? ? ? ? ? ? //alert(flag);? ? ? ? }? ? ? ? ? ? var student_id = $('input[name="student_id"]').val();//獲取input的值? ? ? ? ? ? //alert(student_id);? ? ? ? ? ? $.ajaxSetup({? ? ? ? ? ? ? ? ? async: false//設(shè)置同步? ? ? ? ? ? ? ? ? });? ? ? ? ? ? $.post("user/queryByID", {student_id : student_id},function(data){? ? ? ? ? ? ? ? //alert(data);? ? ? ? ? ? ? ? if (!data) {//校驗(yàn)數(shù)據(jù)是否為空? ? ? ? ? ? ? ? ? ? alert("查無此人");? ? ? ? ? ? ? ? ? ? flag = false;? ? ? ? ? ? ? ? ? ? //alert(flag);? ? ? ? ? ? ? ? }? ? ? ? ? ? });? ? ? ? //alert("======"+flag);? ? ? ? return flag;? ? }controller? ? @RequestMapping(value = "/queryByID", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")? ? public Student queryByID(Integer student_id, HttpServletRequest request) {//根據(jù)id校驗(yàn)數(shù)據(jù)是否存在? ? ? ? Student student = userService.getStudent_id(student_id);? ? ? ? /*try {? ? ? ? ? ? if (student.getName() == null) {? ? ? ? ? ? ? ? System.out.println("111");? ? ? ? ? ? } else {? ? ? ? ? ? ? ? System.out.println("有");? ? ? ? ? ? ? ? System.out.println(student_id);? ? ? ? ? ? }? ? ? ? } catch (Exception ex) {? ? ? ? ? ? System.out.println(ex.getMessage());? ? ? ? ? ? System.out.println("沒有");? ? ? ? }*/? ? ? ? return student;//將查詢到的數(shù)據(jù)返回給ajax,沒有返回null? ? }
總結(jié)
以上是生活随笔為你收集整理的ajax学生校验学号,ajax校验数据库数据是否存在的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: weex css单位,Weex系列(7)
- 下一篇: 服务器错误重启mysql错误信息,mys