0
我正在尋找一種方法來運行一個函數,當$ http調用獲取超時。在XMLHttpRequest中有一個叫做ontimeout的事件處理程序,但是我找不到在$ http中在AnguarJS中執行此操作的方法。任何解決方案AngularJS中的XHR ontimeout()?
$http.get('http://10.255.255.1/test', {withCredentials: true})
.then(function(response, error) {
console.log('then');
console.log(response, error);
})
.success(function(data, status, headers, config) {
console.log('success');
console.log(status, data);
})
.error(function(data, status, headers, config) {
console.log('error');
console.log(status, data);
});
在這種情況下,它們都不會被調用。此外,它似乎不是GET超時,但OPTIONS。
該案不屬於在失敗回調? '$ http.get(url).then(成功,失敗)'你可以從回調參數中讀取狀態:'function(data,status,headers,config)'。如果你想要全局的東西,你可以註冊一個攔截器 – Guillaume86 2013-04-26 15:36:38
我通常使用.success和.error,但也只是嘗試過,如果有超時/連接問題,它們都不會返回任何東西。 – Patrick 2013-04-26 15:46:06
看起來像一個bug,你能給我你使用的網址,所以我可以在jsfiddle中玩它嗎? – Guillaume86 2013-04-26 15:49:00