$.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