내 코드에 문제가 있습니다. AJAX 호출은 JSON 배열에서 페이지를 입력하는 동안 및 새로 고침 후 정보를 가져 와서 HTML 코드에 원하는대로 넣습니다.하지만 문제는 설정 루프 (30 초)에서 수행하지 않습니다.정기 AJAX 통화가 서버 상태를 업데이트하지 않습니다.
이자바 스크립트 :이
$(function status_ts3(){
$.ajax({
url : '/lib/ts3_stats.php',
type : 'POST',
dataType : 'json',
success : function (response) {
$('#ts3-status').replaceWith(response['server_status']);
$('#ts3-number-online').replaceWith(response['online_number']);
},
error : function() {
$('#ts3-status').replaceWith('<span class="server-offline">Offline</span>');
$('#ts3-number-online').replaceWith('<span class="online-number-ts3">0/0</span>');
},
complete: function() {
setTimeout(status_ts3, 30000);
}
})});
PHP :
$ts3 = TeamSpeak3::factory("serverquery://@xxx/?server_port=xxx");
$status = $ts3->getProperty("virtualserver_status");
$count = $ts3->getProperty("virtualserver_clientsonline") - $ts3->getProperty("virtualserver_queryclientsonline");
$max = $ts3->getProperty("virtualserver_maxclients");
$servers_ts3='<span class="server-online">' . ucfirst($status) .'</span>';
$online_number_ts3 = '<span class="online-number-ts3">' . $count . '/' . $max . '</span>';
$ajax = array(
'server_status' => $servers_ts3,
'online_number' => $online_number_ts3,
);
echo json_encode($ajax);
그래서 질문은, 왜 작동하지 않습니다 여기 내 코드는? 내가 뭔가를 놓치거나 오해 했습니까? 나는 반 뉴비 다. 그래서 나는 정말로 모르고있다, 모든 도움에 감사 할 것이다.
개발자 콘솔의 모든 항목은 무엇입니까? –
음, 콘솔에 오류가 없습니다. – szuszi