jquery的ping插件://要用的需要明白代码及自己改些地方
(function($) {
$.fn.ping = function(options) {
var opts = $.extend({}, $.fn.ping.defaults, options);
var stime = new Date().getTime();
return this.each(function() {
var ping, requestTime, responseTime ;
var target = $(this);
function ping(){
$.ajax({url: opts.getUrl(target.html())+'/'+ Math.random() + '.html', //设置一个空的ajax请求
type: opts.type,
dataType: 'html',
timeout: opts.timeout,
beforeSend : function() {
requestTime = new Date().getTime();
},
complete : function() {
responseTime = new Date().getTime();
ping = Math.abs(requestTime - responseTime);
$('#'+target.html().replace('.','_')).text(ping + opts.unit);
//target.text(ping + opts.unit);
}
});
}
var etime = new Date().getTime();
if(Math.abs(stime - etime)<opts.timeout){
ping(); //无论如何都要执行一次
opts.interval != 0 && setInterval(ping,opts.interval * 1000);
}
});
};
$.fn.ping.defaults = {
type: 'GET',
timeout: