I have the following script below that is inside a 6 second interval.
I am trying to loop through a DIV container that has a number of div’s and each div has an ID set to an instructor code for identification. Now I want to loop through this container…grab each ID one at a time and test to see if it is still present in the database. If present then it means the instructor is still online and then I will set the CSS to show “online”.
For some reason my code loops through each ID and THEN it calls the ajax function to execute the check.
setInterval(function() {
$('.instructors_container table').each(function(){
var i_code = $(this).closest('div').attr('id');
console.log(i_code);
// Test to see if i_code is online
$.ajax({
type:"POST",
url: "get_number_instructors_online.php",
dataType: 'text',
data: {i_code:i_code},
success: function(response) {
var answer = response;
console.log(answer);
if(answer == "online"){
var online = "<div class='i_online'></div>";
$('#'+i_code).find("td:first").html('').append(online);
}else{
var offline = "<div class='i_offline'></div>";
$('#'+i_code).find("td:first").html('').append(offline);
}
},
});
})
}, 6000); // every 6 seconds