【发布时间】:2018-09-16 13:27:46
【问题描述】:
我在快递方面有这个功能:
// Register user login
exports.register_user = function(req, res) {
var portalID = req.body.portalID;
var companyName = req.body.companyName;
var password = req.body.password;
var password2 = req.body.password2;
var salt = bcrypt.genSaltSync(12);
var hash = bcrypt.hashSync(password, salt);
password = hash;
var params = {
TableName: "HouseAccounts",
Item: {
"portalID": portalID,
"companyName": companyName,
"points": 0,
"password": password,
}
}
res.sendStatus(200);
}
这个在前端获取:
function register() {
fetch("MyURL/register", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"portalID": document.getElementById("portal-id").value,
"companyName": document.getElementById("company-name").value,
"password": document.getElementById("password").value,
"password2": document.getElementById("password2").value
})
}).then(function(response){console.log(response)});
}
在快递方面,我可以接收通过 POST 发送的 JSON 并对这些数据进行处理。但是,在我的前端,我没有收到快递方面的回复。连接超时,状态为(failed),控制台出现错误Uncaught (in promise) TypeError: Failed to fetch。
【问题讨论】:
-
这可能之前已经解决了。你试过这个吗? stackoverflow.com/questions/42754388/…
-
@JackJefferies 是的,我已经尝试记录 response.json() 但我根本没有收到任何来自 api 调用的返回。
-
因为你什么也没发送。只是一个
200响应头。没有从服务器端发送数据 -
服务器日志中有任何内容吗?没有错误?当您发送
res.json(...)作为测试时会发生什么? -
@FabianTe 想通了
标签: javascript express