2016-07-22 15 views
-2

我需要顯示一些消息,刷新頁面或稍後重試,如果有一個服務器的通信問題,沒有互聯網連接,或Ajax請求沒有迴應等等。我可以在控制檯上找到所有這些錯誤消息。我如何觸發這些消息?如何在發生錯誤顯示消息(說沒有互聯網連接)的jQuery

這樣的事情。谷歌的Gmail也有類似的東西。

enter image description here

+1

你讀過的'$。阿賈克斯()'函數的文檔? – nnnnnn

+0

的可能的複製[檢查與jQuery互聯網連接(http://stackoverflow.com/questions/20043215/check-internet-connectivity-with-jquery) –

回答

1

退房Check Internet connectivity with jquery

在代碼

check_connectivity.is_internet_connected().done(function() { 
    //The resource is accessible - you are **probably** online. 
}).fail(function(jqXHR, textStatus, errorThrown) { 
    alert(0,"oops","No Internet Connection"); 
}); 

當然,你可以用任何你想要的造型取代alert()並顯示它是這樣的這一部分。

相關問題