我正在发送一个请求,它需要很长的时间才能响应,同时我还发送了另一个请求,它完全独立于第一个请求,但第二个请求只有在第一个请求完成时才会被处理。即使在第一个请求完成之前,路由更改也会显示为挂起状态
请帮我解决这个问题。
发布于 2018-08-17 08:08:47
您应该尝试将第二个请求发送到第一个请求的回调中。
例如:
// First GET Request:
$http.get('/firstUrl').then(function(response) {
// Start second request after the first is finished.
return $http.get('/secondUrl');
}).then(function(response) {
// Change route or something else with the second response
console.log(response);
});这样,第二个请求只能在第一个请求完成时启动,您还可以在启动另一个请求之前处理第一个请求获得的响应对象。
https://stackoverflow.com/questions/51878799
复制相似问题