zoukankan      html  css  js  c++  java
  • Ajax提交数据判断员工编号是否存在,及自动填充与员工编号所对应的员工姓名。

    JSP页面中所需要的JavaScript事件及Ajax
    
     1 <script type="text/javascript">
     2 function checkEmpNo(id){
     3     var empNoValue=document.getElementById(id).value;
     4         $.ajax({
     5         type:'post',
     6             url:'employee_checkEmpNoAndEmpName.htm',
     7             data:'empNo='+empNoValue,
     8             success: function(result){      
     9                 if(result=="该用户名不存在!"){
    10                    alert("该用户名不存在!");
    11                    document.getElementById(id).value="";
    12                    document.getElementById("empName").value="";
    13                    document.getElementById(id).focus();
    14                 }else{
    15                    document.getElementById("empName").value=result;
    16                    
    17 } 18 }); 19 </script> 20 <form> 21   <table> 22     <tr> 23       <td><input id="empNo" onblur="checkEmpNo(this.id)" type="text" name="empNo" /></td> 24       <td><input id="empName" type="text" name="empName" /></td> 25     </tr> 26   </table> 27 </form>
    
    
    后台Action所需的代码:

    public
    clasee empAction extends ActionSupport{ public String checkEmpNoAndEmpName() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse respons = ServletActionContext.getResponse(); String empNo = request.getParameter("empNo");//获取页面提交给后台的Action的empNo respons.setContentType("text/html;charset=utf-8");//对响应的字符集进行设置 String sendStr = ""; List<EmployeeInfo> employeeInfoList = this.empService.checkEmpNo(empNo);//调用业务根据empNo层查询此用户 try { PrintWriter out=respons.getWriter();//多去打印对象 if (employeeInfoList.size()>0) { sendStr = employeeInfoList.get(0).getEmpName(); } else { sendString = "该用户名不存在!"; } out.print(sendStr);//将后台动态sendStr输出到JSP页面 out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return null; } }
  • 相关阅读:
    Christmas Jump(k_push)
    cloudyarn(k_push)
    Eye sketch
    Candy Treasure Box
    Active Ball
    Lotus words
    Super Fish
    [POJ2436] Disease Management
    [bzoj3376] Cube Stacking 方块游戏
    [POJ3009] Curling 2.0
  • 原文地址:https://www.cnblogs.com/staticking/p/6808181.html
Copyright © 2011-2022 走看看