1
My difficulty is after sending to java script how to separate each record:
Example: In my code I’m running this function:
$culturas=array();
$resultado=mysqli_query($conexao,"select *from mandioca_iea where id_cult=1");
while($cultura=mysqli_fetch_assoc($resultado))
{
array_push($culturas,$cultura);
}
echo json_encode($culturas);
And to receive the consultation:
$.post('envia.php', {nome: nome}, function(resposta) {}
So far so good, he sends Javascript something like this:
On my console returned this :[{"iea_id":"1","man_ins_area_00":"0","man_ins_prod_00":"0","man_ins_area_05":"0", "man_ins_prod_05":"0","man_ins_area_10":"0","man_ins_prod_10":"0","man_ins_area_13":"0", "man_ins_prod_13":"0","id_cid":"1","id_cult":"1"}, {"iea_id":"2","man_ins_area_00":"0","man_ins_prod_00":"0","man_ins_area_05":"0", "man_ins_prod_05":"0","man_ins_area_10":"0","man_ins_prod_10":"0", "man_ins_area_13":"0","man_ins_prod_13":"0","id_cid":"2","id_cult":"1"}]
Where :"iea_id":"1" and "iea_id":"2",are two different records.
My doubt is if there is any way access the "records" (because in this format are no longer records),separately,as if it were a vector,for mounting a chart?
EDITING WITH THE ERROR:
Complete code being used:
<script type="text/javascript" language="javascript">
$(function($) {
$("#formulario").submit(function() {
$("#status").html("<img src='loader.gif' alt='Enviando' />");
$.post('envia.php', {nome: nome}, function(resposta) {
for(var i=0; i<resposta.length; i++) {
var registro = resposta[i];
console.log(registro.iea_id);
}
});
});
});
</script>
When I run the code on my console appears only:166 Undefined. On this line: console.log(record.iea_id); // 1 in the first step, 2 in the second, has an idea of what it is?
– Rodolfo Oliveira
The data are those that are in question even? It seems that the first id comes 166, and the second blank.
– bfavaretto
The data are those, only I put 2 only, in vdd it returns +- 600 records, I will edit the post with an error picture for you to better understand
– Rodolfo Oliveira
Edited as full code and error image
– Rodolfo Oliveira
you can give a
console.log(typeof resposta)
?– bfavaretto
Check this error:" Uncaught Typeerror: Illegal Invocation"
– Rodolfo Oliveira
Are you sure you wrote as in my comment? This error there should not be generated by the code I mentioned.
– bfavaretto
I put this:$("#status"). html("<img src='Loader.gif' alt='Sending' />"); $. post('send.php', {name: name}, Function(reply) { console.log(typeof reply); . O erro que deu foi esse: Uncaught TypeError: Illegal invocationjquery.js:6 x.param.ojquery.js:6 gnjquery.js:6 gnjquery.js:6 gnjquery.js:6 x.paramjquery.js:6 x.extend.ajaxjquery.js:6 x.each.x.(anonymous function)index2.php:43 (anonymous function)jquery.js:5 x.event.dispatchjquery.js:5 x.event.add.v.Handle
– Rodolfo Oliveira
Dude, I don’t know what could be going on, try a
resposta = $.parseJSON(resposta)
before the loop.– bfavaretto
To work the only library you need is jquery né?
– Rodolfo Oliveira
Yeah, just the jQuery...
– bfavaretto