Ajax feedback from PHP

Asked

Viewed 51 times

1

Friends have a procedure in php where there is a "for" loop, every time it returns to the beginning it triggers information that is received in the Jquery/Ajax function that triggers it. The point is that the data is only displayed to the user at the end of the loop and I needed the data to be made available every time php returned the information, follow an example of what I need.

//função em ajax
function teste(){
$.ajax({
   type:'POST',
   url:'fiscal/teste',
   data:{
        ids:obj //obj é um array de ids de uma seleção em um grid
        },
   success: function (data) {
     $("#debug").text(data);
         },
   })
}

//Função em PHP
public function teste(Request $req){
    $i=0;
    while ($i<=10){
        print_r($req->ids[$i]);
        $i++;
        sleep(1);
    }
}

this code only makes the data available to the client when the while ends.

  • And you need the result of print_r is sent to the client even without having finished the loop?

  • That would be https://pastebin.com/jywWA1T7 ?

  • Anderson, actually the print_r (that only eh print_r to exemplify but could be a Return or echo) is sent every passage in the loop, the problem is qie p Ajax so passes to the view when the loop ends, returning all data at once on the screen, but in fact this routine will make the transmission of tax notes and as the webservice of the carioca note only accepts 150 rps at a time and the customer transmits at least 900 I need him to divide in blocks of 150 and to each dispatch he informed that sent the block 1 2 3 etc, but it even does only that it only displays in the view when everything has already been sent

  • Valdeir, I believe my question is not in php but in ajax, even so thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.