So I have html form send data via ajax to php like:
index.html
<script type="text/javascript">
$("#button").click(function(){
var ajaxname=$("#name").val();
$.ajax({
method:"POST",
url:"some.php",
data:"name="+ajaxname,
success:function(data){
$("#formresult").html(data);
}
});
}
</script>
<form>
<input type="text" name="name" id="name">
<input id="button" type="button" value="send"/>
</form>
<div id="formresult"></div>
and php file like:
some.php
<?php
$name = $_POST['name'];
if($name == "mahdi"){
echo 'true' . '<br/>';
echo 'welcome' . '<br/>';
echo 'have good time!' . '<br/>';
}
else{
echo 'false' . '<br/>';
echo 'wrong name' . '<br/>';
}
?>
When form submit and AJAX callback success, show all of echo in one moment and together. but I want echo "delay in time" for example 2 sec between any echo.
I used "sleep(2);" in php, "setTimeout" and "for loop" in JavaScript, but no one does not work.
Please anybody know the answer put it in https://jsfiddle.net/ to see it work.