本文介绍了表单编辑模式数据为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单编辑中遇到模态ajax的问题​​

我的控制器:

i have problem with modal ajax in form edit
my controller:

public function edit()
	{
		$id=$this->uri->segment(3);
		
		
		$data=array(
		'project' => $this->m_inputactivity->get_project(),
		'actype' => $this->m_inputactivity->get_actype(),
		'detail' => $this->m_inputactivity->per_id($id),
		'details'=> $this->m_inputactivity->show_employee($this->session->userdata('nik')),
		);
		
		
		$this->output
                ->set_content_type('application/json')
                ->set_output(json_encode($data));
	}



我的观点:


my view:

<a title="Edit" class="btn btn-outline btn-circle btn-sm purple">
 Edit </a>
										
										
										
										
<!-- begin pop update activity -->
			<div class="modal fade left" id="modal_form"> 
			<div class="modal-dialog"> 
			<div class="modal-content"> 
			
				<div class="modal-header"> 
					<h3 class="pull-left no-margin">Edit Activity</h3>
					<button type="button" class="close" data-dismiss="modal" title="Close"><span class="glyphicon glyphicon-remove"></span>
					</button> 
				</div> 
				<div class="modal-body">
				
					<form class="form-horizontal" role="form" method="post" action="input_activity/update"> 

					<div class="form-group"> 
						<label for="name" class="col-sm-3 control-label">Kategori:</label> 
						<div class="col-sm-9"> 
						
							
						</div> 
						</div> 
					<div class="form-group"> 
						<label for="activity" class="col-sm-3 control-label">Rincian Kegiatan: </label> 
						<div class="col-sm-9"> 
							<textarea class="form-control" rows="3" name="activity_name"  required></textarea>
						</div> 
					</div> 
					<div class="form-group"> 
						<label for="project" class="col-sm-3 control-label">Peruntukkan:</label> 
						<div class="col-sm-9"> 
						 
						
						</div> 
					</div> 
					<div class="form-group"> 
						<label for="portion" class="col-sm-3 control-label">Bobot:</label> 
						<div class="col-sm-4"> 
						
							<input class="form-control" name="portion"  required>
							<input name="activity_detail_id" type="hidden" id="activity_detail_id">
						</div> 
					</div> 
					<div class="form-group"> 
					<div class="col-md-offset-3 col-md-5">
						<button type="submit" class="btn green">
						   Update</button>
						 <button type="button" class="btn default" data-dismiss="modal">Cancel</button>
					</div>
					</div> 
					</form>

				</div>
				<div class="modal-footer"> 
					
				</div> 
			</div> 
			</div> 
			</div>
<script type="text/javascript">
function edit(id)
{
   
    $.ajax({
        url : "/" + id,
        type: "GET",
        dataType: "JSON",
        success: function(data)
        {

           
			
            $("[name='actype']").val(data.actype);
            $("[name='activity_name']").val(data.activity_name);
			$("[name='project']").val(data.project);
            $("[name='portion']").val(data.portion);
            $('#modal_form').modal('show'); // show bootstrap modal when complete loaded
            

        },
        error: function (jqXHR, textStatus, errorThrown)
        {
            alert('Error get data from ajax');
        }
    });
}

function reload_table()
{
    table.ajax.reload(null,false); //reload datatable ajax 
}
</script>



我的型号:


my model:

function per_id($id)
	{
		
		$this->db->where('activity_detail_id',$id);
		$query=$this->db->get('t_trx_activity_detail');
		return $query->result();
	}





我的尝试:



What I have tried:

i have tried but actually data still empty when pop up edit show

推荐答案




这篇关于表单编辑模式数据为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 18:39