<script type=”text/javascript” src=”/js/jquery-1.4.4.min.js”></script>//引用Jquery
<script type=”text/javascript” src=”/js/jquery-1.4.4.min.js”></script>//引用Jquery//调用方法
<?php echo ‘<a href=”#” onclick=”ajaxupdate(‘.$data->id.’,’.$type.’,\’txt\’,\’pudate\’)”>更新</a>’;?>//JqAjax<script type=”text/javascript”> //id,type,val参数 //url控制器方法 function ajaxupdate(id,type,val,url) { url=”<?php echo Yii::app()->request->baseUrl;?>/index.php/site/”+url; var val1=$(“#”+val+id).val();//动态获取input中的值
var pars = “id=”+id+”&type=”+type+”&val=”+val1; $.ajax({ type: “POST”,//以POST方法接收表单数据 url: url, data: pars, dataType : “html”, success: function(msg){ $(“.classbox”).html(msg);//在class=”classbox”的节点内插入Ajax返回信息 }}); } function isdel(id,type,val,url){ if(!confirm(‘确定要删除这条数据吗?’)){ return false; }else{ ajaxupdate(id,type,val,url); } } </script>
//site控制器中的update更新方法 public function actionupdate(){ $id = $_POST['id']; $val =$_POST['val']; $type=$_POST['type']; $model=myClass::loadModel($id); $model->title=$val; if($model->save()){ echo ‘<div>更新成功</div>’; }else{ echo ‘<div>更新失败</div>’; } Yii::app()->end(); }