我當前的窗口URL http://192.168.20.2/vtp/attendance/rawAttendance
和參數表單通過這個URL "<?php echo base_url(); ?>index.php/attendance/submitParam"
在ajax中提交。有了這個代碼下面如何獲取當前窗口的URI最後一段
$last = $this->uri->total_segments();
$data['lastSegment'] = $this->uri->segment($last);
我拿到了最後的URL部分,但這不是當前窗口的URL段,這是參數形式的URL段。當我提交參數表單時,如何獲取我當前的窗口URL最後一段在我的submitParam controller
中。
提交參數;
$("#submitparam").click(function (e) { // passing down the event
$.ajax({
url: "<?php echo base_url(); ?>index.php/attendance/submitParam",
type: "POST",
data: $("#param").serialize() + '&fromAjax=' + true,
success: function (data) {
$("#result").html(data);
},
error: function() {
alert("Fail")
}
});
e.preventDefault(); // could also use: return false;
});
控制器:
public function submitParam() {
//post from view param
$round = $this->input->post('round', TRUE);
$batch = $this->input->post('batchid', TRUE);
$fromdate = $this->input->post('FromDate', TRUE);
$todate = $this->input->post('ToDate', TRUE);
//raw Attendance
$data['IDS'] = $this->AttendanceModel->raw_attendance_TID($batch);
$data['Dates'] = $this->AttendanceModel->raw_attendance_Data($batch,$fromdate,$todate);
//get Batch Attendance
$data['attendance'] = $this->AttendanceModel->get_attendance($batch,$fromdate,$todate);
//pass param to preview as attendance title
$data['batch']=$batch;
$data['fromDate']=$fromdate;
$data['toDate']=$todate;
//get url last segment
$last = $this->uri->total_segments();
$lastSegment = $this->uri->segment($last);
//load view by url last segment
if ($this->input->post("fromAjax")) {
$this->load->view('attendance/'.$lastSegment, $data);
}
}
好主意先生。 –