Home >Backend Development >PHP Tutorial >yii ajax update data

yii ajax update data

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-28 08:25:561000browse

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)",
			))'
		),

Use JS to set the default selected checkbox
//checkbox 默认选中事件
	$(document).ready(function () {
		var checkboxs = document.getElementsByName("isblock");
		for (var i=0;i<checkboxs.length;i++) {
			var val = checkboxs[i].value;
			var e=checkboxs[i];
			if(val=='Y'){
				e.checked= true;
			}else{
				e.checked=false;
			}
		}
	});

Finally transfer the data to the background
	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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn