There are two files:
1) index.html
<form id="myForm">
<textarea rows="10" cols="45" name="field1"></textarea>
<input type="submit" value="Send">
</form>
<div id="content"></div>
<script>
$(document).ready(function(){
$('#myForm').submit(function(){
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "test.php",
data: str,
success: function(html){
$("#content").html(html);
}
});
return false;
});
});
</script>
2) test.php
<?php
$field1 = $_POST['field1'];
echo "Hello, <b>".$field1."</b>!<br>";
echo "Time: " . date("H:i:s") . "<br/>" . "
";
sleep(5);
echo "Done";
?>
I send to form:
Masha Dasha Peter Sasha
These are a list , separated by .
How to consistently transfer data using the ajax, in the php file to the output that:
Hello, Masha
Time: 10:06:00
ok
Hello, Dasha
Time: 10:06:05
ok
Hello, Peter
Time: 10:06:10
ok
Hello, Sasha
Time: 10:06:15
ok
The data should appear on the page, gradually, in this case 5 seconds may receive a prize of a subsequent action after receiving echo "ok"; I suppose that the first of these to get into the js array, wherein the separator is , gradually feed php, pre-opening session.
Note: The option to give the array in php, its subsequent expansion and echo sending is not suitable, since a large volume of incoming data is a high load, which will increase the expectation and may cause an error, and the gradual release of information in html can be no question .
P.S. Sorry for my bad English