首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Javascript Ajax Get

Javascript Ajax Get
EN

Stack Overflow用户
提问于 2013-03-26 04:38:24
回答 3查看 936关注 0票数 0

我正在尝试让javascript加载和刷新实时数据。但我无法让它显示任何数据。

下面是我的代码:

代码语言:javascript
复制
<!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文件返回以下内容:

代码语言:javascript
复制
{"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>"}

我甚至不能让它显示数据。我需要在我的服务器上安装一些特殊的东西来运行这段代码吗?

EN

Stack Overflow用户

发布于 2013-03-26 05:41:44

更改:

代码语言:javascript
复制
function scheduleStatsUpdate() {
   stats_timer = setTimeout('updateStats();',6000);
}

通过

代码语言:javascript
复制
(function scheduleStatsUpdate() {
  stats_timer = setTimeout('updateStats();',6000);
})();
票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15624294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档