获取 API 延迟
Fetch API Delay
我正在尝试使用请求的提取 API 在我的服务器上提取数据,但该请求需要永远处理(它最终会处理)。我使用 React 作为我的视图,Express 为我的页面提供服务。我在下面列出了我的 Express 和 JSX 代码。了解为什么会发生这种情况('mounted' 消息会按预期立即记录,但在延迟后获取 API)?
快递:
app.use('/test',function(){
console.log('connected');
})
React.JS:
componentDidMount(){
console.log('mounted');
fetch('./test').then(function(response){
console.log(response);
}).catch(function(error){
console.log(error);
})
}
您必须在服务器端发送响应:
app.use('/test',function(request, response){
console.log('connected');
response.send(); //!!!!! this line
//Or: response.sendStatus(200); to send status code without body
});
...否则端点不会终止。
我正在尝试使用请求的提取 API 在我的服务器上提取数据,但该请求需要永远处理(它最终会处理)。我使用 React 作为我的视图,Express 为我的页面提供服务。我在下面列出了我的 Express 和 JSX 代码。了解为什么会发生这种情况('mounted' 消息会按预期立即记录,但在延迟后获取 API)?
快递:
app.use('/test',function(){
console.log('connected');
})
React.JS:
componentDidMount(){
console.log('mounted');
fetch('./test').then(function(response){
console.log(response);
}).catch(function(error){
console.log(error);
})
}
您必须在服务器端发送响应:
app.use('/test',function(request, response){
console.log('connected');
response.send(); //!!!!! this line
//Or: response.sendStatus(200); to send status code without body
});
...否则端点不会终止。