1
I have a code in javascript that sends some elements of the page to another in PHP via ajax and there are made some comparisons. Then it returns me this array with the function print_r() :
However, I would like to use the return for a second comparison only with javascript, but I don’t know how to do it. There is a way to go through this return with a for javascript?
[EDITED]
The object I pick up on the page I convert to json like this:
var data = JSON.stringify(jsonArr);
And it stays that way:
{"forum":[{"user":"AdministradorGabrielOliveira","tempo":"2017-08-26T16:39:31-03:00","vis":1}]}
Then I send it to the PHP page
$.ajax(
{
type: 'post',
url: 'verifica.php',
data: 'data=' + data,
success: function(ret) {
console.log(ret);
}
Some treatments are done and return with the print_r() function of PHP, so it comes to page where I want to do some operations with javascript:
stdClass Object
(
[forum] => Array
(
[0] => stdClass Object
(
[user] => AdministradorGabrielOliveira
[tempo] => 2017-08-26T16:39:31-03:00
[vis] => 0
)
[1] => stdClass Object
(
[user] => AdministradorGabrielOliveira
[tempo] => 2017-08-24T04:57:13-03:01
[vis] => 0
)
)
)
[RESOLVED]
On the PHP page, I put it like this:
<script>
var mandar = <?php echo json_encode($jsonTratado); ?>
</script>
So, going back to the javascript page, I edited the ajax function to display the variable send, brought from there:
$.ajax({
type: 'post',
url: 'verifica.php',
data: 'data=' + data,
success: function(ret) {
console.log(mandar);
}
);
And to iterate I used the foreach as suggested by the colleague in answering this question, I only needed to pass the name of the object array I was looking for, which in my case is "forum"
$.ajax({
type: 'post',
url: 'verifica.php',
data: 'data=' + data,
success: function(ret) {
mandar['forum'].forEach(function(indice){
console.log(indice.user);
console.log(indice.tempo);
console.log(indice.vis);
});
}
);
Could put the Ajax code to know how does this send.
– Guilherme Nascimento
I sent the part of the code I use to send. ;)
– GOliveira
This using json_encode for return?
– Guilherme Nascimento
I am. I have an idea. I will post to receive the tips if this would be the best solution.
– GOliveira
This returns with utf8 encoding ?
– AnthraxisBR
I am, @Anthraxisbr
– GOliveira