Angularjs中的超時處理

關鍵代碼:

// 定義一個定時器, 設置5s爲請求超時時間 var timer = $timeout(function () { console.log('登陸超時!'); // 模擬提示信息 },5000); // post的數據 var postData = {"name":"ng", "password":"111111"}; // 請求 $http.post('your-login-url', postData, {"timeout": timer}) .success(function(data){ // storage and jump }) .error(function(data){ // tips here }) .finally(function(){ $timeout.cancel(timer); // 移除定時器 });

說明

相關文章
相關標籤/搜索