[求助] yii ajax 怎么用? [ 新手入门 ]
===AjaxForm.php===
<?php
class AjaxForm extends CFormModel
{
public $name;
public $team;
public function rules()
{
return array(array('name', 'required'));
}
}
===AjaxController.php===
<?php
class AjaxController extends Controller
{
public function actionIndex()
{
$model = new AjaxForm();
$this->performAjaxValidation($model);
$this->renderPartial('index', array('model'=> $model));
}
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
{
echo'发送了ajax请求';
echo CActiveForm::validate($model);
Yii::app()->end();
} else { echo '没有发送ajax请求'; }
}
}
===index.php===
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<div>
<?php
$fm = $this->beginWidget('CActiveForm', array('id'=>'user-form', 'enableAjaxValidation'=>true, 'focus'=>array($model,'name'),
));?>
<?php echo $fm->errorSummary($model);?>
<div>
<?php echo $fm->error($model,'name'); ?>
<?php echo $fm->labelEx($model, 'name:');?>
<?php echo $fm->textField($model, 'name');?>
</div>
<div>
<?php echo $fm->error($model,'team'); ?>
<?php echo $fm->labelEx($model, 'team:');?>
<?php echo $fm->textField($model, 'team')?>
</div>
<div>
<?php echo CHtml::submitButton('提交信息');?>
</div>
<?php $this->endWidget() ?>
</div>
请问yii的ajax是焦点离开name表单项的时候发送的么?上面的代码访问为什么没有效果呢?
[attach]305[/attach]
共 6 条回复
-
lz19881123 回复于 2011-08-15 12:58 举报
执着的伢啊!
2lenzi
注册时间:2011-08-05
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱100
- 威望0
- 积分100