0
I have the code below, in which I get an ajax query for a file .php. The problem is that this way, I can only return at the end of the process, with the method success:
, but I need to inform the user of the processing progress that takes place in PHP. How to proceed? I tried the method beforeSend:
but from what the documentation says (and confirmed with a test), it is just a method to do something immediately before sending the request, and nothing else. I need something to interact between the processing on the server and the page on which ajax was launched, that is, for example: in a while {...}
inside the .php
, I need a way to interact with an internal counter I put there ($counter, for example).
Here’s the code:
file . js
$.ajax({
type:'post',
dataType: 'json',
url: 'genTableBible.php',
beforeSend: function(dados){
alert(dados);
},
success: function(dados){
for(var i=0;dados.length>i;i++){
$('#'+xbody).append('<tr class="mudacor"><td class="seleciona" ></td></tr>');
}
}
)}
File . php
<?php
ini_set('memory_limit','-1');
require_once('CLASSES/usuarios.php');
$u = new Usuario;
global $pdo;
$u->conectar("host","mysql.servidor.com.br","user","senha");
$xmsgErro = $u->msgErro;
$sql = $pdo->prepare("SELECT * FROM table LIMIT 400");
$sql->execute();
$cont = 0;
while ($result = $sql->fetch(PDO::FETCH_ASSOC))
{
$cont++; // variável para se comunicar com a página/função de origem
$dados[]=$result;
}
echo json_encode($dados);
?>
see this link: https://github.hubspot.com/pace/docs/welcome/
– Lucas Antonio