$.ajax()post方式请求参数无法传递(一)


转载: https://blog.csdn.net/qq_37164847/article/details/88885917

后台接收参数:

// 删除用户
@PostMapping("/del")
public AppResult<String> del(@Param("userId")long userId){
log.info("删除用户");
log.info("删除用户userId:"+userId);
return AppResultBuilder.success("删除成功", ResultCode.SUCCESS);
}
原始前端传递参数:

              $.ajax({
                  headers: {
                    "Authorization":token//此处放置请求到的用户token
                  },
                  url:posturl, 
                  type: "post",
                  data:{"userId":22},
                  contentType: "application/json",
                  dataType: 'json',
                  async: true,
                   success: function(res) {
                     console.log("提交结果=="+JSON.stringify(res));
                  },
                  error:function() { 
                    console.log("提交失败");
                  } 
                });

后端接收显示是null,解决:

把                  contentType: "application/json",
                  dataType: 'json',

去掉


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM