First of all I've seen and tested the solutions below and none of them worked (they do not retrieve any output).
- https://gist.github.com/db/966388
- What is the cleanest way to get the progress of JQuery ajax request?
- PHP ajax remote call to check progress
So, I'm trying to adapt the code to my needs.. my ajax is the following:
$.ajax({
type: "POST",
url: "/getAll",
data: {name: name, age: age, from_where: from_where},
async: true,
success : function(data) {
console.log(data);
},
});
The problem with success function
is that it is only executed after the whole PHP code is processed (at least for what I have tried).
$loaded = 0;
$total = 18; // just for testing
foreach($cust->find("NY") as $div){
$cust->add($name, $div->description("NY"), $age);
$loaded++;
echo round(floatval(($loaded / $total) * 100), 2) . "%";
// It can't be return instead of echo because it STOPs at the first index
}
The only problem with this code is that success function is only called after performed the whole PHP code. So, I'm seeking for ways to output the percentage during the loop of PHP.
Any ideas?