我有一个视图页面和一个表格。当我单击表中的查看按钮时,必须根据代码从数据库中检索数据,并且必须根据代码显示名称、地点等相关数据。根据代码检索后,我无法传递数据。代码在这里:
控制器:
public function project_show(){//page where all buttons are present
$this->load->view('view_project');
}
public function view_get_id($pcode){
$data['viewrec']=$this->project_model->view_proj($pcode);
$this->load->view('view_project',$data);
}
阿贾克斯:
$('.viewbutton').click(function(){
var pcode = $(this).data('id');
$('#viewmodal'+ pcode).modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
console.log(pcode);
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/project/view_get_id/"+ pcode,
data: {
pcode: pcode,
},
success: function (data) {
$("#viewmodal").modal('hide');
showproject();
}
});
});
showproject() 是一个在成功执行时打开的页面
模型:
public function view_proj($Pcode){
$qresult=$this->db->get_where('Project', array('project_code' => $Pcode));
return $qresult->row();
}
视图:弹出模态的页面:
<button class="viewbutton btn btn-info btn-xs" data-toggle="modal" data-target="#viewmodal" data-id="<?php echo $row->project_code; ?>"><span class = "fa fa-eye"></span> view</button>
模态页面:
<div id="viewmodal" class="modal fade bs-example-modal-lg" ..>
..........
<label class="control-label col-md-3 col-sm-3 col-xs-12">Project Code</label>
<label class="control-label col-md-1 col-sm-3 col-xs-12"><?php echo $viewrec->project_code; ?></label>
当错误状态$viewrec->project_code如未定义或访问非对象变量时,我将如何在模态页面中显示数据
撒科打诨
慕尼黑5688855
相关分类