我正在尝试将日期传递给 ajax 函数,并根据该日期从数据库中单独获取相关类型和标题。
我使用了以下模型 函数。
function get_reservation_for_add_popup($date_cal) {
$this->db->select('reservations.title,reservations.type');
$this->db->from('reservations');
$this->db->where('reservations.date_cal', $date_cal);
$this->db->where('reservations.is_deleted', '0');
$query = $this->db->get();
return $query->result();
}
我的Controller 功能如下
function get_title_and_type() {
$reservation_service = new Reservation_service();
$data['reservation_pop_up'] = $reservation_service->get_reservation_for_add_popup($this->input->post('date', TRUE));
echo $data;
}
在 View 中,我想分别获取特定日期的标题和类型。我使用了以下 ajax 函数。但我不知道如何从 ajax 函数返回值以及如何将它们捕获到变量中。
var date = $('#date').val();
var title=[];
var type=[];
$.ajax({
type: 'POST',
url: '<?php echo site_url(); ?>/dashboard/get_title_and_type',
data: 'date=' + date,
success: function(msg) {
return msg;
}
});
由于我是 ajax 的新手,如果有人给我一个想法,那将是一个很大的帮助。
最佳答案
在ajax中变化如下
data: 'date=' + date,
至
data: {'date' : date},
关于php - CodeIgniter - 如何从 ajax 方法返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31287886/