【发布时间】:2015-03-18 08:24:06
【问题描述】:
我的问题是我无法访问从控制器返回到 ajax 成功函数的数组。
这里是我的控制器代码:
function get_slot()
{
$fac_id = 1;
$date = $this->input->post('date');
$this->load->model('booking_model');
$result = $this->booking_model->get_slot_availablity($date, $fac_id );
$data['booking'] = $result['row'];
echo json_encode($data);
}
我的 ajax 函数:
$.ajax({
type : "Post",
url : "<?php echo base_url(); ?>index.php/index/get_slot",
data : "date="+date,
dataType : 'json',
success : function(result)
{
$.each(result, function(index, val) {
alert(val.slot_id);
});
}
});
我的模型函数:
public function get_slot_availablity($date, $fac_id){
$q = $this->db->select('*')
->from('booking')
->where('f_id', $fac_id)
->where('date', $date);
$res['row'] = $q->get()->result();
return $res;
}
函数显示未定义
【问题讨论】:
-
检查浏览器控制台,你从服务器得到什么?
-
不需要header()先alert(result);在你的成功块中然后开始解析你的 json 数据
-
我已经删除了 header(),并且我添加了 dataType json..但仍然得到未定义的 @RakeshSharma
-
请列出这个
$this->booking_model->get_slot_availablity()函数的代码。 -
我已经编辑了我的问题@Mysteryos
标签: php jquery arrays ajax codeigniter