2
Good morning Guys,
I have an error reading my json array when I call it in my ajax.
My json:
[{"id":"7","nome":"Anderson","sobrenome":"Dorea"},{"id":"6","nome":"Diego ","sobrenome":"Andrade"},{"id":"8","nome":"Marcelo","sobrenome":"Cordova"}]
My ajax function:
$.ajax({
url: 'package/getUser',
type: 'POST',
datatype: 'json',
success: function(data)
{
for(i = 0; i < data.length; i++)
{
console.log(data[i]);
}
},
error: function(data)
{
console.log(data)
}
});
My controller:
function getUser()
{
$this->load->model('packageModel');
$query = $this->packageModel->getUser()->result_array();
echo json_encode($query);
}
It doesn’t pass array by array... it separates each letter when I put it into my for, but I need to play that information in a div with the append, only when I do so they come out as Undefined. Someone who can give me a light?
Try putting before the
for
:data = JSON.parse(data);
– Sam
It worked, now why does this happen? I have other functions in this same capture pattern and did not need to do JSON.parse.
– Diêgo Correia de Andrade