0
I’m looking to list results from a PHP page using jquery, which is updated every 3 seconds, but I’m not getting it. The code I’m using is:
<div id="listar"></div>
<script src="assets/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
function mostrar(){
$(document).ready(function(){
$.ajax({
type:'post',
dataType: 'json',
url: 'atualizar.php',
success: function(dados){
$('#listar').append(dados[0]);
}
});
});
}
//setInterval(function(){ mostrar; }, 3000);
setInterval(mostrar, 3000);
</script>
As an example, I put the PHP code below:
$ver = "teste";
echo json_decode($ver);
The problem is in Jquery and not in PHP ;)
What is going wrong?
– PauloHDSousa
No PHP output shown.
– user24136
I included in the post an excerpt that I forgot
– user24136
Do it inside the Success
console.log(dados)
, and see if any results are coming...– Max Rogério
Would not be
json_encode
that you should be using?– bio
What is the status of the request, 200, 500? You only have the successful callback, put the error too, it may be having trouble parsing..
– BrTkCa
I really switched to json_encode and it worked. I’m sorry for the lack of attention and thank you all.
– user24136