它的工作方式相同。Yii 与 jquery 捆绑在一起,所以你
只需使用 jquery 获取表单字段并进行 ajax 调用
到某个控制器函数,用它做任何你想做的事,并返回一个响应,用 php 的echo
.
如果您已经知道一些 jquery,那么客户端应该与 .net mvc 没有太大区别。
编辑:
要将 a 添加<script>
到生成的 html 中,请参见registerScript。
要创建 url,请使用createUrl函数。
将 ajax 选项添加到 html 标记代码类似于:
echo CHtml::checkBox('mybox',false,
array(// array for htmloptions, we also pass ajax options in here
'class'=>'checkBoxes_class',
'ajax'=>array(// this is ajax options for jquery's ajax
'type'=>'POST',
'url'=>Yii::app->createUrl('xyz',array('clickedboxid'=>'mybox')), // here you passed clickedboxid as a get variable
'beforeSend'=>'function(){}',
'success'=>'',
// etc etc
)
)
);
每个 html 标签生成器辅助函数都接受 htmlOptions 数组,我们也可以在其中传递ajax options。
在控制器中读取这些值时:
public function actionSomeAction($id){
// $id is mybox
echo "Hello"; // this is returned as response to the client
}
希望这足以让您开始。