I have a webpage that calls an AJAX script -
ajax.php. I am using JQuery to send the AJAX requests.
ajax.php receives some arguments via
$_REQUEST, based on that it starts its processing. The processing has multiple steps involved and at the end of the each step I want to send some feedback back to the page - for example:
Once all the steps are completed - the script
ajax.php will output a TXT file which I am outputting via:
header('Content-type: text/plain'); header('Content-Disposition: attachment; filename="output.txt"');
My questions are:
I have a
div in the page where I want to show the user that Step 1 completed, Step 2 completed, ... If I use
JQuery.ajax(), will the
.done function called multiple times? If no, whats the best way to handle it? Can I use
ob_implicit_flush in PHP to send 'Step x completed 'messages?
Finally, how will I handle the output of .txt file so that user's browser downloads it? I don't want to save the file on the server and then going into hassle of server disk space, cron jobs of deletes, etc.
I have the option of doing multiple AJAX requests - but again I don't want to do this as this will make my code logic pretty complex and I will have to save a lot of data in
$_SESSION to be visible across requests which is again something that I don't want to do.