简体   繁体   English

刷新Javascript并获取PHP变量

[英]Refresh Javascript and retrieved PHP variable

After searching for several hours both in this Forum and on the Internet, I finally decided post my Problem... I would like to update a circular progress bar using ajax but I am new to this topic and didn't succeed in transferring different solutions to my Problem. 在这个论坛和Internet上搜索了几个小时之后,我终于决定发布我的问题...我想使用ajax更新循环进度栏,但是我是这个主题的新手,并且未能成功转移其他解决方案我的问题。 Here is the Code: 这是代码:

<script type="text/javascript">
       $('#circle').circleProgress({
       value: 0.75,
       size: 150,
       fill: {
       gradient: ["red", "orange"]
       }
       });
</script>

<script type="text/javascript">
       <?php include "itemCount2.php"; ?> 
       $('#circle').circleProgress('value', <?php echo $count ?>);
</script>

The second script updates my progress bar using the PHP variable $count. 第二个脚本使用PHP变量$ count更新进度条。 The database content is changing dynamically. 数据库内容是动态变化的。 This version is working fine. 这个版本工作正常。 Now I'd like to execute this script every few seconds, automatically updating the progress. 现在,我想每隔几秒钟执行一次此脚本,以自动更新进度。 Can anybody help me? 有谁能够帮助我? Thank you very much in advance! 提前非常感谢您!

progrss.php progrss.php

   $progress['progress']=(int)getProgress(); // it should return data from database i men percentage 
    echo json_encode($progress);

Then in your html add the following code. 然后在您的html中添加以下代码。 Hope jquery library already added. 希望jQuery库已经添加。

$(function() {
var nre = setInterval(checkit, 5000);
function checkit(){
$.ajax({
url: 'http://yoursite/progress.php',
dataType: 'json',
cache: true,
timeout: 300000,
success: function(data) {


$.each(data, function(i,datas){
if(datas.progress<100)
{
// Write your code for circle. 
}
else
{

$('#output').html("complete. "+datas.comment);
clearInterval(nre);
}

});

},
error: function(){
$('#output ul').append('<li>Error');
}
});

}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM