如何消耗与reactjs的提取API? [重复]

问题描述 投票:-1回答:1

在PHP中我已经一个API的,但我想用取Reactjs消耗,但我不能得到的,有人能帮助我吗?

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 => {})
   .then(result => {
      console.log(res);
      return result.json();
   })
 }

错误:enter image description here

邮差的位置:enter image description here

javascript reactjs rest cors fetch
1个回答
-1
投票

尝试

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);
      // work with the result

   })
 }
© www.soinside.com 2019 - 2024. All rights reserved.