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); // 移除定時器 });

說明


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM