問題描述
檢查互聯網/網絡是否存在的Jquery代碼(手機/PC/平板電腦).它必須只檢查頁面加載.我認為Ajax會很好,因為Ajax會在一定間隔后檢查.
Jquery Code which check the internet/network is there or not(mobile/PC/Tablet).It must just check on page load.I thinkAjax will good because Ajax will check after certain interval.
我看起來就像 http://tomriley.net/,但它是插件,我正在尋找簡單的 jquery/Javascript.
I am looking just like http://tomriley.net/, But it is plugin, I am looking for simple jquery/Javascript.
它的靜態頁面只檢查系統互聯網.
Its static page which check system internet only.
任何想法都值得贊賞.
推薦答案
您可以嘗試使用 .fail()
處理程序的 $.ajax()
調用,例如例如 JQuery 的 getJSON()
:
You might try a $.ajax()
invoication with a .fail()
handler, for example JQuery's getJSON()
:
var network_available; // bool
var url = '/some/json/call'; // must be relative to the site that
// you are already addressing
$.getJSON(url, function(data) {
network_available = true;
})
.fail(function() {
network_available = false;
});
雖然我懷疑這會解決你所有的問題.Javascript 引擎不允許外來"URL,只允許接收腳本或頁面的域.因此,您不會真正測試網絡可用性,而是測試您的網站是否已啟動并在合理的時間內響應.
Though I doubt this will solve all of your problems. The Javascript engine won't allow 'foreign' URL's, just the domain that the script or page was received from. So you'd not be really testing network availability, but also whether your site is up and responding within a reasonable time.
這篇關于檢查互聯網的 Jquery/Ajax 代碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!