我的观点 -
$(document).ready(function(){
$(".varsity").change(function(){
var id=$(this).val();
$.ajax({
type: "POST",
url: "<?php echo base_url()?>/admin/get_varsity_faculty",
data:"varsity_id="+id,
dataType: 'json',
success: function(data)
{
alert(data);
}
});
});
});
我的控制器(管理员)
public function get_varsity_faculty()
{
//admin controller
$varsity_id=$this->input->post('varsity_id');
$faculties=$this->admin_varsity->get_faculty_information($varsity_id);
//print_r($faculties);
echo json_encode($faculties);
}
当我认为 print_r($faculties) 和警报响应(删除 dataType:'json')得到这个输出时——
Array
(
[0] => Array
(
[unit_id] => 1
[vid] => 3
[unit_name] => Faculty of Civil Engineering
[form_starting_date] => 2013-05-15
[form_end_date] => 2013-05-22
[admission_date] => 2013-05-22
[possible_result_date] => 2013-05-22
[class_start_date] => 2013-05-21
[is_active] => 1
)
[1] => Array
(
[unit_id] => 2
[vid] => 3
[unit_name] => Faculty of Electrical & Electronic Engineering
[form_starting_date] => 0000-00-00
[form_end_date] => 0000-00-00
[admission_date] => 0000-00-00
[possible_result_date] => 0000-00-00
[class_start_date] => 0000-00-00
[is_active] => 1
)
[2] => Array
(
[unit_id] => 12
[vid] => 3
[unit_name] => Civil Engg
[form_starting_date] => 2013-06-11
[form_end_date] => 2013-06-12
[admission_date] => 2013-06-18
[possible_result_date] => 2013-06-04
[class_start_date] => 2013-06-10
[is_active] => 1
)
)
我的模型工作得很好。但是当我回显 json_encode($faculties); 在我看来,使用 dataType:'json' 我得到了类似 [object] [object] 的响应。并且无法解析响应。我知道这不是一个棘手的问题。但我自己已经尝试了很多次来克服这个问题。总之我的问题是如何获得 json 响应并在我看来从这个数组中解析它。谢谢