javascript - Loop in a json codeigniter object with jquery -


i searched in many questions doesn't worked me, want loop through json object returned controller, let me show code:

model

public function traer_pasajero($id){     $this->db->select('*');     $this->db->from('pasajeros');     $this->db->where('id', $id);     $query = $this->db->get();     return $query->result(); } 

controller

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);             });           }      }); 

}

and receive error in firebug: typeerror: invalid 'in' operand a

this json object see in firebug:

[{"id":"1","primer_nombre":"xxxx","segundo_nombre":"","primer_apellido":"xxxx","segundo_apellido":"","ci":"xxx","nacionalidad":"uruguayo","fecha_nacimiento":"5/7/1910","vencimiento":"5/5/1910","asiento":"12","habitacion":"sgl","levante":"","telefono":"","observaciones":"","id_envio":"2"}]

datatype should "json" instead of "text", , try console.log(data) before each loop.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -