Yii中ajax使用范例(用success代替update)

view
-----------------------------------------------------------------------------
<?php echo CHtml::dropDownList('version',isset($_POST["version"])?$_POST["version"]:"3", $data,
	array('ajax'=>array(
	'type'=>'POST',
	'url'=>Yii::app()->createUrl('tools/setObjectName'),
	//'update'=>'#objtype',
	'beforeSend'=>'function(){jQuery("#objtype").attr("disabled","disabled")}',
	'success'=>'function(data){
		jQuery("#objtype").html(data);
		jQuery("#objtype").removeAttr("disabled");
	}',
)));?>


当update和success都使用了的话,update会失效。


Controller
-----------------------------------------------------------------------------
public function actionSetObjectName(){
	if (isset($_POST["version"])) {
		$data = DataModel::model()->getDataByVersion($_POST["api_version"]);
		foreach($data as $key => $value){
		echo CHtml::tag('option', array('value'=>$key),CHtml::encode($value),true);
		}
	}
}

你可能感兴趣的:(update)