如何取消AngularJS的$ http请求? [英] How to cancel an $http request in AngularJS?
本文介绍了如何取消AngularJS的$ http请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于AngularJS一个Ajax请求
Given a Ajax request in AngularJS
$http.get("/backend/").success(callback);
什么是要取消该请求的最有效的方法,如果另一个请求启动(相同的后端,例如不同的参数)。
what is the most effective way to cancel that request if another request is launched (same backend, different parameters for instance).
推荐答案
此功能已加入通过超时参数的1.1.5版本:
var canceler = $q.defer();
$http.get('/someUrl', {timeout: canceler.promise}).success(successCallback);
// later...
canceler.resolve(); // Aborts the $http request if it isn't finished.
这篇关于如何取消AngularJS的$ http请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文