I have a bootstrap progress bar on my webpage
我的网页上有一个bootstrap进度条
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="70"
aria-valuemin="0" aria-valuemax="100" style="width:70%">
70%
</div>
</div>
My php script -
我的PHP脚本 -
<?php
function get_memory() {
foreach(file('/proc/meminfo') as $ri)
$m[strtok($ri, ':')] = strtok('');
return 100 - round(($m['MemFree'] + $m['Buffers'] + $m['Cached']) / $m['MemTotal'] * 100);
}
echo "".get_memory()."";
?>
When the php function is called, a numeric value is called, which updates.
调用php函数时,会调用一个更新的数值。
Essentially, what I want to do, is
基本上,我想做的是
<?php echo "".get_memory()."";?>
on the style="width:70%" of the progress bar, so the progress bar would dynamically update, using the value reported from the php function.
在进度条的style =“width:70%”上,进度条将使用php函数报告的值动态更新。
I hope that makes sense.
我希望这是有道理的。
I have tried
我努力了
<script>
setInterval(function(){
jQuery.ajax({
url: "ramUsage.php",
success: function(result) {
$('.progress-bar').css("width", data + '%');
},
});
}, 1000);
</script>
This gives me
这给了我
ReferenceError: data is not defined
Wouldn't it be better to use websockets instead of AJAX? If so, how would I do that?
使用websockets代替AJAX不是更好吗?如果是这样,我该怎么做?
1 个解决方案
#1
0
Instead of ,
代替 ,
$('.progress-bar').css("width", data + '%');
You should have to used ,
你应该使用,
$('.progress-bar').css("width", result + '%');
or
$('.progress-bar').css("width", result.responseText + '%');
#1
0
Instead of ,
代替 ,
$('.progress-bar').css("width", data + '%');
You should have to used ,
你应该使用,
$('.progress-bar').css("width", result + '%');
or
$('.progress-bar').css("width", result.responseText + '%');