I have this simple JQUERY code:
$(document).ready(function () {
$(document).on('click', 'button', function(){
$.post('post.php',
{
test: 'yes'
},
function(data, textStatus)
{
alert(data);
});
});
});
And this post.php
page:
<?php
/* do some stuff that takes time */
echo '1';
?>
So i submit a POST request to PHP page using JQUERY and want to alert the response which is 1
in the above example. The problem is that the script takes sometime to fully execute which in return slows down the response.
This is just a very simplified example. Is there a way to get the response before the full loading of the PHP script? I tried to echo before the rest of the script but it doesn't matter as the response won't be sent before the script completes all the tasks.