Bom dia, preciso pegar os pings dos ips e jogar numa tabela com o status deles, se pingou ou não. para isso estou fazendo da seguinte forma:
JavaScript:
[code]function ping(ip, callback) {
if (!this.inUse) {
this.status = ‘unchecked’;
this.inUse = true;
this.callback = callback;
this.ip = ip;
var _that = this;
this.img = new Image();
this.img.onload = function () {
_that.inUse = false;
_that.callback(‘PING’);
};
this.img.onerror = function (e) {
if (_that.inUse) {
_that.inUse = false;
_that.callback('PING', e);
}
};
this.start = new Date().getTime();
this.img.src = "http://" + ip;
this.timer = setTimeout(function () {
if (_that.inUse) {
_that.inUse = false;
_that.callback('ERRO');
}
}, 1500);
}
}
var PingModel = function (servers) {
var self = this;
var myServers = [];
ko.utils.arrayForEach(servers, function (location) {
myServers.push({
name: location,
status: ko.observable('unchecked')
});
});
self.servers = ko.observableArray(myServers);
ko.utils.arrayForEach(self.servers(), function (s) {
s.status('checando');
new ping(s.name, function (status, e) {
s.status(status);
});
});
};
var komodel = new PingModel([
'192.168.1.01',
'192.168.0.48',
'192.168.0.176'
]);
ko.applyBindings(komodel);[/code]
Porém não consigo colocar na tabela pois o IP e o status dele vem juntos e preciso colocar em colunas diferentes. Alguém tem uma ideia de como poderia fazer isso?