我正试图在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网络选项卡中检查)
创建另一个名为AjaxController.php的控制器把这个代码写在那个里。
class AjaxController extends Controller
{
public function actionReqTest01() {
echo date('H:i:s');
Yii::app()->end();
}
}