0
I have a role in jQuery who receives a array from PHP, through the $.post. The array comes like this:
array(
'0' => array(
'ID' => '1',
'NOME' => 'João'
),
'1' => array(
'ID' => '2',
'NOME' => 'Maria'
),
'2' => array(
'ID' => '3',
'NOME' => 'Marcos'
),
)
How do I stop through jQuery, add option in a select with the data from that array?
Example:
<select>
<option value="ID">"NOME"</option>
</select>
This is the $.post that I’m receiving the array from php
$.post('/consulta/usuario', {id:id}, function(dados){
alert(dados);
}, 'json');
I’ll get the id according to the option that the user chooses, and next to php I am returning the array:
echo json_encode($usuario);
What gives
alert(typeof dados);? gives string?– Sergio
@Sergio does not give anything, the box of Alert does not appear
– Fleuquer Lima
See something wrong with your browser tools? see the request made and the return? (Veloper tools > network)
– Sergio
@Sergio after much snooping, I realized that he is giving error because some of the fields of the array are coming with BD accent
– Fleuquer Lima
And fixing that already works? what kind of mistake gave?
– Sergio
@Sergio worked, was giving error on account of utf8, now I managed to do
– Fleuquer Lima