JSON/jQuery를 통해 최근에 활성 사용자를 나열하려고합니다. 그러나이 계산 시스템은 제대로 작동하지 않습니다. 그것은 모두 사용자를 나열하고 "활성 사용자 없음"메시지를 제공합니다. 어떻게 해결할 수 있을까요?JSON 요소를 Jquery로 계산합니다.
감사합니다. 활성 사용자를 잡고
PHP 코드 :
<script type="text/javascript">
//counter for number of JSON elements
var i=0;
//show active users function
function showActiveUsers(){
$('#content').html('');
$('#noActiveUsers').html('');
$.get("array.php", function (activeUsersList) {
$.each(activeUsersList, function (a, b) {
$("#content").append("<tr class=\"userRow\" style=\"display:none\">" + "<td class=\"userId\">" + b.id + "</td>"
"<td class=\"type\">" + b.type + "</td>"
"<td class=\"username\">" + b.username + "</td>"
"<td class=\"lastip\">" + b.lastip + "</td>"
"<td class=\"lastActivityPage\">" + b.lastactivitypage + "</td>" + "</tr>");
$(".userRow").show();
//add to counter of JSON elements
i++;
});
}, "json");
if (i == 0){
$('#heading').hide();
$('#noActiveUsers').append('<h2>There are no active users.</h2>');
$('#noActiveUsers').show('slow');
}
//reset timer
setTimeout("showActiveUsers()", 3000);
}
$(document).ready(function() {
showActiveUsers();
});
</script>
왜 모두가이 질문에 반대 투표합니까? 내 말미에 올바르게 형식화되었지만 이제는 @ dakshbhatt21의 수정 사항을 받아 들였습니다 – sixli