Answer the question
In order to leave comments, you need to log in
How to cancel sent $http requests in AngularJS?
Good day to all! There are 2 functions, one sends a $http request with a command to start execution, the second one checks the progress every 500 ms, that is, a step-by-step execution display script. In the success of the first request (completed 100%), I output console.log('закончили выполнение');
However, the field of this console message slips more answers from the second function, which checks the progress.
After sending the first request, I start $interval autoUpdate = $interval($scope.ajaxRequest, 500);
and in success I cancel it if (autoUpdate) $interval.cancel(autoUpdate);
How to kill sent $http requests after the response has arrived?
Answer the question
In order to leave comments, you need to log in
The config object that accepts $http has a timeout key that either accepts directly max. request execution time as a number, or a promise that, if resolved, cancels the request.
var cancel = $q.defer();
$http({..., timeout: cancel.promise});
cancel.resolve(); // Отменит выполнение запроса
I understand correctly that you want to send a request to the web server that will cancel the execution of other previously sent requests? At the level of the theory of HTTP requests - NO way. In practice, the web server does not know at all that one single request is somehow related to others previously sent. How long does it take to process a general request? second-10-100?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question