问题是
“未处理的拒绝(SyntaxError):输入意外结束”
&CORB(跨域读取阻止)。
我的代码是
handleSubmit(event){
event.preventDefault();
const data = new FormData(event.target);
fetch('http://api.valios.net/user/signup',
{
method:'POST',
mode:'no-cors',
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
},
body: data,
})
.then(response => response.json()) //handle json response
.then(responseJson => {
console.log(responseJson);
});
}
答案 0 :(得分:0)
您放置了无心跳和Cross原点的标头,您可以按以下方式更改代码
handleSubmit(event){
event.preventDefault();
const data = new FormData(event.target);
fetch('http://api.valios.net/user/signup',
{
method:'POST',
mode:'cors',
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
},
body: data,
})
.then(response => response.json()) //handle json response
.then(responseJson => {
console.log(responseJson);
});
}
致谢