我不确定 ibook 仪表板,但我为我的网络应用程序编写了一个心跳检查器,可用于确认 http 连接,也许它可以做你需要的......原始帖子在这里
您使用要检查的 URL、最大 ttl 和回调调用代码。如果页面在 ttl 结束时(以毫秒为单位)没有响应,则使用 null 调用回调,否则您将获得状态和请求对象。
function heartbeat(url, ttl, callback) {
// Confirms active connection to server by custom URL response
//
if (!url) {
url = "http://www.yourwebsitehere.com/yourpage?someheartbeatcall";
// Replace with specific server heartbeat location and query string for cache busting
}
if (!ttl) {
ttl = 1000; // Custom timeout in milliseconds
// Replace with specific server heartbeat location and query string for cache busting
}
// Create the Ajax object
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
}
catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
// Unable to create
callback(null);
return;
}
}
}
// Set flag so only one pulse is recorded
var called = false;
// Make ajax call
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
if (!called) {
called = true;
callback(ajaxRequest.status, ajaxRequest);
}
}
}
ajaxRequest.open("GET", url, true);
ajaxRequest.send(null);
// Make ttl timeout call
var ttlcatch = setTimeout(function(){
if (!called) {
called = true;
callback(null);
}
}, ttl);
return;
}
var foo = false;
heartbeat("http://www.google.com", 1000, function(pulse){alert(pulse);} )