有没有办法传递已经加载的视图的参数。我的控制器使用包含round, batch, fromDate, toDate
的表单加载页面,然后当我单击通过ajax提交并将数据作为模型的参数发布时。我从模型中得到的变量也将通过我加载的视图。
控制器:
public function rawAttendance(){
$round = $this->input->post('round',TRUE);
$batch = $this->input->post('batchid',TRUE);
$fromdate = $this->input->post('FromDate',TRUE);
$todate = $this->input->post('ToDate',TRUE);
$user_data['userinfo'] = $this->logindatamodel->login_data();
$data['round'] = $this->AttendanceModel->get_round();
$data['IDS'] = $this->AttendanceModel->raw_attendance_TID($batch);
$data['Dates'] = $this->AttendanceModel->raw_attendance_Data($batch);
$this->load->view('common/header', $user_data);
$this->load->view('common/menu', $user_data);
$this->load->view('viewParam',$data);
$this->load->view('attendance/rawAttendance', $data);
$this->load->view('common/footer');
}
脚本:
$("#submitparam").click(function(e){ // passing down the event
$.ajax({
url:"<?php echo base_url(); ?>index.php/attendance/rawAttendance",
type: "POST",
data: $("#param").serialize(),
success: function(data){
$("#result").html(data);
},
error: function(){
alert("Fail")
}
});
e.preventDefault(); // could also use: return false;
});
答案 0 :(得分:1)
根据讨论,请执行以下更改
你必须像这样加载ajax调用所需的内容。
首先从ajax传递另一个变量,
data: $("#param").serialize() + '&=fromAjax' + true,
接下来在控制器中,
if($this->input->post("fromAjax"){
$this->load->view('attendance/rawAttendance', $data);
} else {
$this->load->view('common/header', $user_data);
$this->load->view('common/menu', $user_data);
$this->load->view('viewParam',$data);
$this->load->view('attendance/rawAttendance', $data);
$this->load->view('common/footer');
}