检查互联网的 Jquery/Ajax 代码

Jquery/Ajax Code which check the internet(检查互联网的 Jquery/Ajax 代码)

本文介绍了检查互联网的 Jquery/Ajax 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查互联网/网络是否存在的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 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:检查互联网的 Jquery/Ajax 代码

基础教程推荐