Jquery/Ajax Code which check the internet(检查互联网的 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 代码


基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01