您的位置:首页 > 其它

ajax 请求后台数据

2017-11-26 14:57 113 查看
//jsp中ajax请求
$.ajax({
     type: "POST",//请求方式 

     url:
"../display",//地址,就是action请求路径 

     data:
"method=getNum1",//数据类型text xml json  script jsonp
     dataType:"json",//指定返回值的类型
     success:
function(msg){//返回的参数就是 action里面所有的有get和set方法的参数
          }
     },error:function(msg)
     {
        console.info("error!!!");
        console.info(msg);
     } 
  });   
 //servlet 

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Content-Type", "text/html; charset=UTF-8");
String method=request.getParameter("method");
if(method.equals("getNum1"))
{
getNum1(response);
}
}

public void getNum1()
{
  ...
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: