检查互联网的Jquery / Ajax代码 [英] Jquery/Ajax Code which check the internet
问题描述
我看起来就像 http://tomriley.net/ ,但它是插件,我正在寻找简单的jquery / Javascript。
它的静态页面只检查系统互联网。
任何想法是赞赏的。
您可以尝试 $。ajax()
使用 .fail()
处理程序进行调用,例如JQuery的 getJSON()
:
var network_available; // bool
var url ='/ some / json / call'; //必须是相对于
的站点//你已经在寻址
$ .getJSON(url,function(data){
network_available = true;
})
.fail(function(){
network_available = false;
});
虽然我怀疑这会解决您的所有问题。 Javascript引擎将不允许'外部'网址,只是脚本或网页的域名。所以你不会真的测试网络可用性,而且你的网站是否在合理的时间内启动和响应。
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.
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.
Any idea is appreciated.
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;
});
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代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!