下面是一个ajax的请求,红色标注的就是解决办法
$.ajax({
url: ' api/json', //数据地址
data: JSON.stringify({"username": username, "password": password}),
type: "POST", //请求方式
dataType: "json",
contentType: "application/json;charset=UTF-8",
success: function (data) {
if (data.errcode == 0) {
// console.log(111)
window.location.href = "http://localhost:1234/home.html";
} else {
showErr(data.errmsg);
return false;
}
}
})