Jquery 如何在cakephp中每秒自动刷新div数据
我快发疯了,cakephp表中有以下代码:Jquery 如何在cakephp中每秒自动刷新div数据,jquery,cakephp,Jquery,Cakephp,我快发疯了,cakephp表中有以下代码: <td style="width:50%"> <div id="progress<?=$turnTime['TurnTime']['name'];?>"> <?php if ($turnTime['TurnTime']['end_time'] < date('Y-m-d H:i:s')) { echo __('Waiting...');
<td style="width:50%">
<div id="progress<?=$turnTime['TurnTime']['name'];?>">
<?php if ($turnTime['TurnTime']['end_time'] < date('Y-m-d H:i:s')) {
echo __('Waiting...');
}else{
$percent = ((strtotime($turnTime['TurnTime']['end_time']) - strtotime(date('Y-m-d H:i:s')))/
(strtotime($turnTime['TurnTime']['end_time']) - strtotime($turnTime['TurnTime']['start_time'])))*100;
$p = 'width: '.round($percent, 2).'%';
//show the time left
$current_date = new DateTime(date('Y-m-d H:i:s'));
$since_current = $current_date->diff(new DateTime($turnTime['TurnTime']['end_time']));
echo $since_current->h.' hours - '.$since_current->i.' minutes - '.$since_current->s.' seconds Left';
?>
<div class="progress progress-striped active" id="bar">
<div class="bar" style= "<?php echo $p; ?>"></div>
</div>
<?php } ?>
</div>
</td>
试一试
函数showText()
{
var hidden_field=$('#progress_get_me').val();
$(“#进度”+隐藏的_字段).html(…这里的一些代码;
}
$(函数()
{
设置间隔(showText,1000);
});
setInterval调用错误
问题是:
设置间隔(showText(),1000)
它将每秒调用showText
的结果,但是showText
没有返回值(更不用说返回函数),因此它只在文档准备就绪时有效地调用showText
要修复此错误,请使用:
setInterval(showText, 1000);
它将每秒调用函数showText
。您在这个问题上使用了AJAX标签,因此我建议使用AJAX。-1这包含与调用函数setInterval
相同的错误question@AD7six你什么意思?我已经测试过了,没有错误…请在-1…thanx之前检查以进行投票…比较,然后查看我的答案;)@AD7six我不知道我的答案出了什么问题。。??我已经通过浏览器测试过了。。。你能让我知道,这样我就可以纠正我自己吗?另外,“程序员创建的函数必须声明为外部”不是真的。“第三,在你想使用的时候使用隐藏字段”这似乎是基于类似的误解而提出的建议。
<script>
$(document).ready(function(){
setInterval(showText(), 1000);
function showText(){
//alert("11");
$("#progress<?=$turnTime['TurnTime']['name'];?>").html(....some codes here...);
}
});
</script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
function showText()
{
var hidden_field = $('#progress_get_me').val();
$("#progress"+hidden_field).html(....some codes here...);
}
$(function()
{
setInterval(showText, 1000);
});
</script>
<input type="hidden" value="<?=$turnTime['TurnTime']['name'];?>" id="progress_get_me" />
setInterval(showText, 1000);