In my php home page, i have a form with around 10 to 60 fields. and when i submit it to "process.php" page it will process each field one by one and outputs the result. But this will output the results as whole. what i want to do is, submit the data using ajax and collect the output one by one and display it to user one bye one.
I have read jquery get, post and ajax methods. But how do i echo output one by one from the php page and each is collected by ajax and displayed it to user one by one ?
I kno that i can do ajax calls one by one(send one field and get response, then display it to user and send next field, so on). But i do not want to do like that. I want to send all fields in a single click and display output one by one.
This process.php use an API(using curl). So it may take some seconds delay.
Is it possible ?
More details:
$fields = $_POST['flds'];
foreach($fields as $f)
{
// do cURL operation - API
// print output
}
so output will be like:
output of field1
.....
output of field2
.....
output of field3
.....
etc..
ie, first it will display:
output of field1
after some seconds:
output of field1
output of field2
and goes like this. I donot want to send one field and get output and then second field and then output, etc. But i want to send whole fields and get output one by one.
is it possible ?
Similar: flush() Not displaying output in PHP?
What i tried for testing:
<?php
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
$i = 10;
while($i>0)
{
echo $i . '<br />';
flush();
sleep(1);
$i--;
}
?>
but not working. Page looks like loading for some seconds and finally outputs the numbers as whole.
REASON for asking this question is, this api takes 4-11 seconds or more for a single execution ! So above 50 fields it will take about 10 minutes. even if extend max execution time of script user have to wait with that blank screen for this much time!