繁体   English   中英

SyntaxError:JSON.parse:JSON数据第1行第1列的数据意外结束[了解更多]

[英]SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data[Learn More]

请一个我不能解决这个问题,有人可以帮助我吗?

handleSubmit = event => {

event.preventDefault();
const email = document.querySelector(".email").value;
const senha = document.querySelector(".password").value;

alert(JSON.stringify({email, senha}));

const res = {
   method: 'POST',
   mode:'no-cors',
   body: JSON.stringify({email,senha}),
   headers: new Headers({
     'Content-type': 'application/json',
     'Authorization': 'Token Here',
   }),
 };
 fetch('http://rhvagas-api/login', res).then(res => res.json())
 .then(result => {
    console.log(result);
 })
}

错误:

在此处输入图片说明

邮差:

在此处输入图片说明

我认为您的身体对象存在问题,因为您只是将价值传递给身体而没有钥匙。 因此主体应为body: JSON.stringify({email:email, password:senha})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM