【发布时间】:2014-11-13 12:27:51
【问题描述】:
我正在尝试在 Yii 的 Ajax 中发出一个简单的 ajax 请求
我有我的视图文件views/items/index.php 和一个控制器文件controllers/ItemsController.php
我在我的视图文件中插入了一个链接
echo CHtml::ajaxLink(
'Test request', // the link body (it will NOT be HTML-encoded.)
array('ajax/reqTest01'), // the URL for the AJAX request. If empty, it is assumed to be the current URL.
array(
'update'=>'#req_res'
)
);
?>
<div id="req_res">...</div>
我的控制器文件中有这段代码
public function actionReqTest01() {
echo date('H:i:s');
Yii::app()->end();
}
但是什么都没有发生,它给出了错误 404(在 chrome 网络选项卡中检查)
【问题讨论】:
-
对我来说很好。 actionReqTest01() 是否在 AjaxController.php 中?
-
我不想要单独的。我在模型的索引视图中使用它,所以我已将此控制器操作放置在该模型的控制器中,这是错误的吗?