乡亲
尝试通过邮件发送表单数据时出现错误400的问题。但我找不到错误在哪里:
也许是本地主?
function sendUser() {
const form = document.getElementById("cad");
if (submit) {
submit.addEventListener("click", function () {
let user = new User(
form.userProfile.value,
form.name.value,
form.lastname.value,
form.email.value
);
fetch('http://localhost:8080/api/auth/register-user', {
method: 'POST',
body: JSON.stringify(user),
headers: new Headers({
'Content-Type': 'application/json'
})
}).then(function (response) {
if (response.ok) {
return response.json();
} else {
return Promise.reject({
status: response.status,
statusText: response.statusText
});
}
}).catch(function (error) {
console.log('Looks like there was a problem: \n', error);
});
})
}
}
我可以使用jquery来做到这一点
var settings = {
"url": "http://10.1.2.10:8080/api/auth/register-user",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Cache-Control": "no-cache",
},
"data": JSON.stringify(user)
}
$.ajax(settings).done(function (response) {
console.log(response);
});