I am actually using a PHP script that takes some time to execute. It does echo strings every second, for let's say 1 min. What I am trying to do is to "echo" these strings into my HTML page. When I call my function inside my page, it works nicely, it executes when the page loads, and echo a string each second :
<h1> Here is my func </h1>
<?php my_func();?>
But not I'd like to show this when I am sending a form (because I will use the form as parameters of my function). So I tried something like this :
<form method="POST" action="">
<input name='param' value='param'type='text'/>
</form>
<script>
$.ajax({
url:'phpfileWithMyFunc.php',
data: {
param : param
},
dataType: 'json',
type:'post'
)}.done(function (data){
$('body').append(data);
});
</script>
This one doesn't work at all, no idea why.
So I tried something else, with $.post
:
<form method="POST" action="">
<input name='param' value='param'type='text'/>
</form>
<script>
$('#form').submit(function () {
$.post('phpfileWithMyFunc.php', { param: param }, function(result) {
$('tbody').append(result);
});
return false;
});
</script>
Finally, this one works, but my php file has to finish his execution (waiting 1 minute in my case), to have my results happened.
So I'm here to ask, is there any way to do as I was executing my PHP file "inside" my HTML file, so each time I echo a string it displays instantly on my HTML (every second in my case), instead of waiting for the end of my script?
Thanks for helping.