【发布时间】:2019-02-12 01:34:23
【问题描述】:
我有一个用 PHP 制作的 API,但我想通过 fetch 使用 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();
})
}
【问题讨论】:
-
在 fetch 中使用的 URI (rhvagas-api/login) 和 Postman 中显示的 URI (rhvagas-api/user/login) 之间也存在差异。这可能是你的问题吗?
标签: javascript reactjs rest cors fetch