I'm with the back of a website that is a store, and I'm preparing the typical balloons that are on top of the cart, to notify you how many orders there are new on the web, check them in the database.
Script with which I check and print every 3000
<script>
(function($) {
var fnConsulta = function(){
$.ajax({
url : 'totalpedidos.php', // URL donde se encuentra el archivo php
type : 'POST', // Puede ser GET
success : function( resp ){ // Función que procesará la respuesta (JSON)
// Aquí ya puedo mostrar los globos con la respuesta
$( "#respuestaTotalPedidos" ).html( resp );
},
error: function(){
alert( 'Ocurrió un error' );
}
});
};
fnConsulta();
//Ahora va el código del timer, llamará al php cada minuto
timerConsulta = setInterval(function(){
fnConsulta();
}, 3000);
})(jQuery);
</script>
On the same page I have a span with id = # answerTotalPedidos
<li class="nav-item dropdown cuenta" style="margin: 5px 5px 0 0 !important;">
<i class="icon-basket"></i><span id="respuestaTotalPedidos" class=""> </span>
</li>
On the other hand the query to check in the DB
<?php
$globos = $mysqli->query("SELECT count(*) as total from pedidos WHERE status=0");
while($data = $globos->fetch_array()== 0){
echo $data['total'] ? $data['total'] : 0 ;
}
?>
What happens is that the balloon does not show me anything, and it seems that the refresh works well, because in the inspector it loads the query every 3 sec.