Home >Backend Development >PHP Tutorial >yii ajax update data
1. Set it as an input box, enter and modify it in the list
Set an onchange event for timelimit
'columns'=>array( 'id', array('name' => 'platform', 'value' => '$data->platform'), array('name' => 'version', 'value' => '$data->version'), array('name' => 'build', 'value' => '$data->build'), array('name' => 'uptime', 'value' => '$data->uptime'), array( 'name' => 'timelimit', 'type' => 'raw', //输入框 'value' => 'CHtml::textField("timelimit",$data->timelimit,array( "size" => 25, //边框大小 "class" => "txt_timelimit", //设置样式 "id" => "$data->id", //当前数据id "onchange" => "checkedField(this.value,$data->id,1)", ))' ),)transmits the data to the background for update
//更新 function checkedField(val,id,flag){ updateApp(id,val,flag); }
function updateApp(id,val,flag) { if(confirm("确认修改?")){ $.ajax({ url : 'UpdateApp', type : 'POST', data : {"id":id,"val":val,"flag":flag}, dataType : 'json', success:function (json) { //成功获得的也是json对象 if(json.flag){ alert("修改成功") $(this).val(json.val); window.location.reload(); } } }) } }2. Operate the checkbox
Add the following code under columns
array( 'name' => 'isblock', 'type' => 'raw', //输入框 'value' => 'CHtml::checkBox("isblock",$data->isblock,array( "id" => "$data->id", //当前数据id "value" => "$data->isblock", "onchange" => "check_isblock(this.checked,$data->id,3)", ))' ),
//checkbox 默认选中事件 $(document).ready(function () { var checkboxs = document.getElementsByName("isblock"); for (var i=0;i<checkboxs.length var val="checkboxs[i].value;" e="checkboxs[i];" if e.checked="true;"><br>Finally transfer the data to the background <pre code_snippet_id="1769269" snippet_file_name="blog_20160718_6_5310079" name="code"> function check_isblock(ischeck,id,flag) { var val = ischeck?'Y':'N'; // updateApp(id,val,flag); }
The above introduces the yii ajax update data, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.