【发布时间】:2014-05-29 21:04:58
【问题描述】:
我搜索了很多问题但对我没有用,我想遍历控制器返回的 json 对象,让我给你看代码:
型号
public function traer_pasajero($id){
$this->db->select('*');
$this->db->from('pasajeros');
$this->db->where('id', $id);
$query = $this->db->get();
return $query->result();
}
控制器
public function traer_pasajero(){
$pasajero = $this->pasajeros_model->traer_pasajero($this->input->post('id'));
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($pasajero));
return $pasajero;
}
JS
function modificarPasajero (id) {
$.ajax({
type: "POST",
url: "http://localhost/xxx/xxx/traer_pasajero",
data: {id: id},
dataType: "text",
cache:false,
success:
function(data){
$.each( data, function( key, value ) {
alert(value);
});
}
});
}
我在 firebug 中收到此错误: TypeError: 'in' 操作数 a 无效
这是我在 firebug 中看到的 json 对象:
[{"id":"1","primer_nombre":"xxxx","segundo_nombre":"","primer_apellido":"xxxx","segundo_apellido":"","ci":"xxx" ,"nacionalidad":"乌拉圭","fecha_nacimiento":"5/7/1910","vencimiento":"5/5/1910","asiento":"12","habitacion":"Sgl"," levante":"","telefono":"","observaciones":"","id_envio":"2"}]
【问题讨论】:
标签: javascript php jquery json codeigniter