求 一个 servlet jquery ajax mysql增删改查 简单例子

如题,谢谢了!
2025-05-08 13:15:23
推荐回答(1个)
回答1:

假设:
1、你的页面在Web-Root下,内容为:  

,所用编码为utf-8
2、你的servlet为:  HelloWorldServlet.java  映射路径为   servlet/helloWorldServlet
步骤:
1、引入jquery-1.6.4.min.js
2、编写id为userName的输入框的点击触发函数:

     $("#userName").keyup(function(){
            $.ajax({
                  type: "post",
                  url: "servlet/helloWorldServlet?userName="+$(this).val(),
                  dataType: "json",
                  success: function(data){
                        $("#showMsg").html(data.msg);//修改id为showMsg标签的html
                  }, error: function(){
                        alert("请求出错");
                  }
            })
      })