1、ajax数据的封装
var json = {"token":token};//封装json数据 $.ajax({ url:'', data:JSON.stringify(json),//封装成json dataType:"JSON", type:"POST", async:false, cache:false, contentType:'application/json;charset=UTF-8',//必须添加 success:function(data){ }, error:function(data){ textmsg("请求错误,请联系客服人员!"); } });
2.后台接收
@ResponseBody @RequestMapping("checkLogin") public String checkLogin(HttpServletRequest request,HttpServletResponse response,@RequestBody JSONObject jsonObject){ System.out.println("----------------i am checkLogin"); String token = jsonObject.get("token")==null?"":jsonObject.getString("token"); //或者使用 String token = request.getParameter("token")==null?"":request.getParameter("token"); }