2013-03-25 2 views
0

javascript에서 라이브 데이터를로드하고 새로 고치려고합니다. 그러나 나는 그것을 보여줄 수 없다.Javascript Ajax Get

Heres는 내 코드 :

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> 
</head> 

<script type="text/javascript"> 

function updateStats() { 
    $.ajax({ 
     type: 'GET', 
     url: "http://localhost/data.php", 
     dataType: 'json', 
     success: function(data) { 
      $('#sysstats').html(data.sysstats); 
      $('#aststats').html(data.aststats); 
      scheduleStatsUpdate(); 
     }, 
     error: updateFailed 
    }); 
} 
function scheduleStatsUpdate() { 
    stats_timer = setTimeout('updateStats();',6000); 
} 
</script> 

<body> 


<div id="aststats" class="infobox ui-widget-content ui-corner-all"> 

</div> 
<div id="sysstats" class="infobox ui-widget-content ui-corner-all"> 

</div> 
</body> 

Data.php 파일은 이러한 내용을 반환 : 나는 심지어 데이터를 표시 할 수 없습니다

{"sysstats":"<h3 class=\"ui-widget-header ui-state-default ui-corner-all\">System Statistics<\/h3><h4>Processor<\/h4><div class=\"databox\" style=\"width:200px;\">\n <div class=\"dataname\">Load Average<\/div>\n <div class=\"datavalue\"><a href=\"#\" title=\"Load Average: 0.01\">0.01<\/a><\/div>\n<\/div>\n<div class=\"databox graphbox\" style=\"width:200px;\" title=\"CPU: 0.00 \/ 100 (0%)\">\n <div class=\"bargraph graphok\" style=\"width:0px;\"><\/div>\n <div class=\"dataname\">CPU<\/div>\n <div class=\"datavalue\">0%<\/div>\n<\/div>\n<h4>Memory<\/h4><div class=\"databox graphbox\" style=\"width:200px;\" title=\"App Memory: 527.67MB \/ 2010.453125MB (26%)\">\n <div class=\"bargraph graphok\" style=\"width:52px;\"><\/div>\n <div class=\"dataname\">App Memory<\/div>\n <div class=\"datavalue\">26%<\/div>\n<\/div>\n<div class=\"databox graphbox\" style=\"width:200px;\" title=\"Swap: 0.00MB \/ 760.8828125MB (0%)\">\n <div class=\"bargraph graphok\" style=\"width:0px;\"><\/div>\n <div class=\"dataname\">Swap<\/div>\n <div class=\"datavalue\">0%<\/div>\n<\/div>\n<h4>Disks<\/h4><div class=\"databox graphbox\" style=\"width:200px;\" title=\"\/: 2.53GB \/ 30.18GB (8%)\">\n <div class=\"bargraph graphok\" style=\"width:16px;\"><\/div>\n <div class=\"dataname\">\/<\/div>\n <div class=\"datavalue\">8%<\/div>\n<\/div>\n<div class=\"databox graphbox\" style=\"width:200px;\" title=\"\/boot: 0.01GB \/ 0.10GB (10%)\">\n <div class=\"bargraph graphok\" style=\"width:20px;\"><\/div>\n <div class=\"dataname\">\/boot<\/div>\n <div class=\"datavalue\">10%<\/div>\n<\/div>\n<div class=\"databox graphbox\" style=\"width:200px;\" title=\"\/dev\/shm: 0.00GB \/ 0.98GB (0%)\">\n <div class=\"bargraph graphok\" style=\"width:0px;\"><\/div>\n <div class=\"dataname\">\/dev\/shm<\/div>\n <div class=\"datavalue\">0%<\/div>\n<\/div>\n<h4>Networks<\/h4><div class=\"databox\" style=\"width:200px;\">\n <div class=\"dataname\">eth0 receive<\/div>\n <div class=\"datavalue\"><a href=\"#\" title=\"eth0 receive: 0.00 KB\/s\">0.00 KB\/s<\/a><\/div>\n<\/div>\n<div class=\"databox\" style=\"width:200px;\">\n <div class=\"dataname\">eth0 transmit<\/div>\n <div class=\"datavalue\"><a href=\"#\" title=\"eth0 transmit: 0.00 KB\/s\">0.00 KB\/s<\/a><\/div>\n<\/div>\n","aststats":"<h3 class=\"ui-widget-header ui-state-default ui-corner-all\">FreePBX Statistics<\/h3><div class=\"databox graphbox\" style=\"width:400px;\" title=\"Total active calls: 0 \/ 18 (0%)\">\n <div class=\"bargraph graphok\" style=\"width:0px;\"><\/div>\n <div class=\"dataname\">Total active calls<\/div>\n <div class=\"datavalue\">0<\/div>\n<\/div>\n<div class=\"databox graphbox\" style=\"width:400px;\" title=\"Internal calls: 0 \/ 18 (0%)\">\n <div class=\"bargraph graphok\" style=\"width:0px;\"><\/div>\n <div class=\"dataname\">Internal calls<\/div>\n <div class=\"datavalue\">0<\/div>\n<\/div>\n<div class=\"databox graphbox\" style=\"width:400px;\" title=\"External calls: 0 \/ 18 (0%)\">\n <div class=\"bargraph graphok\" style=\"width:0px;\"><\/div>\n <div class=\"dataname\">External calls<\/div>\n <div class=\"datavalue\">0<\/div>\n<\/div>\n<div class=\"databox graphbox\" style=\"width:400px;\" title=\"Total active channels: 0 \/ 36 (0%)\">\n <div class=\"bargraph graphok\" style=\"width:0px;\"><\/div>\n <div class=\"dataname\">Total active channels<\/div>\n <div class=\"datavalue\">0<\/div>\n<\/div>\n<h4>FreePBX Connections<\/h4>"} 

. 이 코드를 실행하려면 서버에 특별한 설치가 필요합니까?

+0

로? –

+0

방화 광구를 사용하여 실제로 데이터를 제대로 보내고 받고 있는지 확인하십시오. – Ryoku

+0

''로 호출 해 보았습니다.하지만 작동하지 않았습니다. –

답변

0

시작하는 함수를 호출해야합니다. 귀하의 아약스 전화 또는 시간 초과,하지만 당신이 실행하려는 생각 :

 setInterval(function() { 
     updateStats(); 
    }, 6000); 

대신에.

+0

'window.onload = function updateStats() {}'시도했지만 데이터를 가져 오지만 데이터를 가져 오는 오전. –

0

$ ('# sysstats')을 (를) 호출하는 이유 .html (data.sysstats); ? .... "sysstats"id가있는 요소가 없다고 생각합니다. 대신 "aststats"또는 "sysinfo"ID가 있습니다. ...

+0

그것은 오타 였지만 여전히 작동하지 않습니다. aststats 및 sysstats가로드되어야하지만 둘 다로드되지 않습니다. –

0

변경 :

function scheduleStatsUpdate() { 
    stats_timer = setTimeout('updateStats();',6000); 
} 

당신은()`최초`updateStats를 호출

(function scheduleStatsUpdate() { 
    stats_timer = setTimeout('updateStats();',6000); 
})();