你的问题不是很清楚。我想您想在 div 中设置内容的自动和定期刷新,而不是单击按钮。
这是您页面上需要的 JavaScript:
<script type="text/javascript">
timeout = 60 * 1000; // in Milliseconds -> multiply with 1000 to use seconds
function refresh() {
<?php
echo CHtml::ajax(array(
'url'=> CController::createUrl("blog/UpdateAjax?url=".$url),
'type'=>'post',
'update'=> '#inrscrn',
))
?>
}
window.setInterval("refresh()", timeout);
</script>
但是,将 URL 发送到您的控制器并不是一个好方法,而是直接请求对需要返回对应数据的控制器进行特殊的 AJAX 返回。
<?php
public function actionTest(){
if (isset($_REQUEST['AJAX']) || Yii::app()->getRequest()->getIsAjaxRequest()) {
$this->renderPartial(
'test',
array('model' => $model),
false,
true
);
} else {
$this->render(
'test',
array('model' => $model),
);
}
}
?>