检查互联网的 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 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

opening html from google drive(从谷歌驱动器打开 html)
Google apps script get range of bytes from binary file(谷歌应用程序脚本从二进制文件中获取字节范围)
Sending Multiple attachments with Google Script from Google Drive(使用 Google 脚本从 Google Drive 发送多个附件)
Distributing Google Apps Scripts for Sheets in your company network(在您的公司网络中分发适用于表格的 Google Apps 脚本)
Upload file to my google drive from anyone using javascript(使用 javascript 将文件从任何人上传到我的谷歌驱动器)
quot;Shared Drivequot; support in Google Apps Script(“共享驱动器Google Apps 脚本中的支持)