1
My Ajax request is returning 3 records of a PHP query (yes, I’m sure), so we have arrays of the type:
array 1 ["João", "19/05/1986", "masculino", "Programador", "Campo Grande"]
array 2 ["Maria", "15/05/1988", "feminino", "Enfermeira", "Londres"]
array 3 ["Patricia", "04/11/1980", "feminino", "Servidora Pública", "Fortaleza"]
Question: How do I separate this data so that I can take the information of each array separately and continue my system? To help I’ll put a piece of code
$.ajax({
type: "POST",
dataType: "json",
url: "<?php bloginfo('template_url'); ?>/scripts/php_functions.php",
data: {
idClienteDocumentos: idClienteDocumentos,
ajax: "true"
},
success: function(result) {
var resultado = JSON.parse(result);
// preciso montar as arrays cujo contador me confirmou que existem
$("#Contador").val(resultado[6]);
For those who feel free to give a little extra strength, I need to put this inside a while PHP.
What gives you
typeof result
andresult.length
?– Sergio
You caught me because I’m still super beginner in jQuery and I don’t know how to get this information! It can help me to know how I get to this data?
– Marcos Vinicius
No problem. Do it like this:
alert('Tipo: ' + typeof resultado + ', length: ' + resultado.length);
on the line belowvar resultado = JSON.parse( etc...
– Sergio
I found this in the OS en foreach in Javascript
– Jader A. Wagner
Type: string Lenght: 83 ....
– Marcos Vinicius
Hmmm this after JSON.parse? using
resultado
in the Alert?– Sergio
Right after JSON Alert(result);
– Marcos Vinicius
can you put the code you have in php that echo to ajax? something is wrong there I think
– Sergio
Why does your PHP code return an array instead of objects (people, I imagine)?
– danguilherme
http://pastebin.com/6f3q7kBC ... this is the PHP code I’m using to fetch the results that are returning the arrays. This is the image I have of Alert: http://puu.sh/aEhSh/035bdea5ad.jpg ... This is the return of the console: http://puu.sh/aEhVN/1f0832ef96.png. (has 4 records) which I obtained using this code: http://puu.sh/aEi1V/76f478677f.png
– Marcos Vinicius
Daguilherme, sometimes for lack of knowledge I expressed myself badly, it may be that it is returning objects even.
– Marcos Vinicius
@marcosvinicius but then made the Alert before from JSON.parse, I wrote "in the line below". So it’s better
– Sergio
@Sergio, excuse me, you’re right. I just tidied up and returned this: http://puu.sh/aEiaC/e1bc18564c.png
– Marcos Vinicius
Good. Explain me one more question: what do you mean by " I need to put this inside a while PHP"?
– Sergio
I have a table with inserted files related to each user. So let’s say a user has 5 file records, I need a while to return the 5 records as shown in the image: http://puu.sh/aEikI/2535685976.png
– Marcos Vinicius
So it means something like a while from PHP but in javascript/client side?
– Sergio
Let’s go continue this discussão in chat.
– Marcos Vinicius