【发布时间】:2019-10-22 23:15:08
【问题描述】:
我正在尝试在 react 中使用 axios 调用 api。我正在使用 express 和 node js。当使用 axios.get() 调用 api 时。它在一段时间后返回错误。当我在端口 4000 中运行节点时(localhost :4000/data) 它没有加载。
//api
router.route('/issue').get((req, result) => {
Issue.find((err, issue) => {
if (err)
console.log(err);
else
result.json(issue);
});
});
//api call in react file
axios.get('http://localhost:4000/issue').then(res=>{
console.log('success');
}).catch(err=>{
console.log('error');
});
【问题讨论】:
-
你到底得到了什么错误信息?
-
错误情况下你没有响应请求...
-
它等待响应并返回此错误' GET localhost:4000/issue net::ERR_EMPTY_RESPONSE '
标签: node.js reactjs mongodb express axios