jquery ajax post get 提交请求后台服务器是,发送信息至服务器时内容编码类型。cententType详解

ajax请求后台controller的时候发送过去的内容编码类型:

类型一:contentType: “application/json; charset=utf-8”,
类型二:contentType: “text/xml”,
类型三:contentType:”application/x-www-form-urlencoded”,
data:”json”,data:”text”//表示的是从服务器返回的类型

用类型一:contentType: “application/json; charset=utf-8”, 发送数据内容格式给服务器
后台用@RequestBody接收,例子如下:




后台controller:
  @RequestMapping(value = "/doRegister",method=RequestMethod.POST)
    @ResponseBody
/*  public String doRegister(@RequestParam("username") String username  ,@RequestParam(value = "password",required = false) String password
            ,@RequestParam(value = "phone",required = false) String phone ,@RequestParam(value = "idNum",required = false) String idNum
            ,@RequestParam(value = "realName",required = false) String realName){
        logger.info("doRegister() 方法被调用");
             boolean result=userService.registerData(username,phone,password,idNum,realName);*/
    public String doRegister(@RequestBody UserVO uservo){ //实体接收方式
        System.out.println("doRegister= realName===="+uservo.getRealName());
          //注册方法....
        if(result==true){
            return "login";
        }
        return "register";
    }

你可能感兴趣的:(jquery-aja)