我正在从事一个项目,检查多个网站,无论它们是在线还是不在线。我试着使用下面的代码来检查一个著名的网站,作为试用,但它总是返回错误。我怎么才能修复它呢?
function Ping() {
$.ajax({
type: "HEAD",
url: "http://www.google.com",
success: function(result){
alert('reply');
},
error: function (result) {
alert('failure');
}
});
}
window.setInterval(Ping, 10000);发布于 2014-08-05 19:47:18
使用javascript的服务器端代理的替代方法是使用您希望ping的url加载image (new Image()),并在image的onload/onerror事件中检查状态。
例如:
var img = new Image();
img.onload = function(){
// the ip/domain is online
}
img.onerror = function(e){
// the ip/domain is online
}
img.src = 'http://www.google.co.in'; // the ip/domain to ping完整的例子在这里:http://jsfiddle.net/GSSCD/203/
它不是一个完整的解决方案,但需要进一步实施;)
https://stackoverflow.com/questions/19249182
复制相似问题