在用 ajax 的 post 请求是 后端没有接收到参数 ,原因是请求的 Content-Type 还是 json 格式的 。大意了!!!
修改如下:
$.ajax({
//请求方式
type : "POST",
//请求的媒体类型
headers: {
'Content-Type': 'application/x-www-form-urlencoded' //multipart/form-data;boundary=--xxxxxxx application/json
},
//请求地址
url : url+"sign/register",
//数据,json字符串
data : {
'email':email,
'username':userName,
'password':password,
'code':code
},
//请求成功
success : function(data) {
if (data.code=="200"||data.code=='-4'){
alert(data.msg)
window.location.href='login.html';
}
else {
alert(data.msg)
}
},
//请求失败,包含具体的错误信息
error : function(e){
alert("发送失败")
}
});