【发布时间】:2017-10-29 05:59:02
【问题描述】:
我正在使用基本提取从快速服务器获取数据,该服务器从数据库中查询数据。所以我想做一个登录系统,我想通过获取请求从输入字段发送用户/密码。所以我可以执行逻辑检查以查看密码是否与服务器中的数据匹配。并以结果回应。 是否可以做一个可以传递参数的fetch?
更新代码如下:
let fetchData = {
method: "post",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: this.state.user,
password: this.state.password
})
}
var fromServer = fetch('http://localhost:3000/', fetchData)
.then(function(response){
if( !response.ok){
throw Error (response.statusText);
}
return response.json();
})
.then(function(response) {
console.log(response);
})
.catch(error => console.log("there was an error --> " + error));
表达功能
app.post('/', function(req, res){
var uname = req.body.username;
var pw = req.body.password;
console.log(uname);
console.log(pw);
});
【问题讨论】:
标签: fetch