The below script returns 2 Alerts (F3 and S1). I would need 4 alerts (F1, F2, F3 and S1) - that's the host names of all the services.
I guess that the each function is creating an Array that does not contain doublets - so it's only giving me one - the last one F3.
How can I get the host_names
of all the services ? I can not change the input data.
SCRIPT:
<script>
$(function () {
var status = [];
$.ajaxSetup({
cache: false
});
$.getJSON('status.php', function (data) {
$.each(data.services, function (i, f) {
alert(f.host_name);
});
});
});
</script>
OUPUT from status.php:
{
"hosts": {
"modified_host": "0",
"modified_serv": "0"
},
"services": {
"HTTPS": {
"host_name": "F1",
"service_description": "HTTPS"
},
"HTTPS": {
"host_name": "F2",
"service_description": "HTTPS"
},
"HTTPS": {
"host_name": "F3",
"service_description": "HTTPS"
},
"HTTP": {
"host_name": "S1",
"service_description": "HTTP"
}
}
}