之前写了一个demo,用ajax异步发送请求,后端一直无法接收到参数。排查了很久,少加了请求头。前两天在一个交流群也发现群友遇到同样的问题。所以想记录一下Layui的这个坑。遇到过两次了。
前端:Layui
后端:Springboot
直接上代码,Ajax请求,最重要的就是这一行
contentType: "application/json; charset=utf-8",
下面是ajax的请求的完整代码
function read(noticeId) {
S.ajax(
url:localhost:8080 + "/nothord/adList",
data:{ userId:id},
type:"post",
dataType:"json" ,
contentType: "application/json; charset=utf-8",
success:function(response){
console.log(response)
},
error:function(error){
console.log(error)
}
)
}