I have a series of buttons on a page that when a user clicks on them they trigger a PHP script via jQuery .ajax()
. Currently, I append a concatenated string dump of "progress updates" to a status placeholder DIV via the success: function(data) { $('#divplaceholder').append(data); ...}
parameter. My problem is I would like to print real-time progress updates to that placeholder DIV as the execution "echoes" them.
I have read many SSE examples, tutorials, done extensive googling and I think I have an idea on how to send the "messages" back from the server but I have been unable to find an example on how to actually trigger tasker.php via jQuery to send the updates back when the user actually pushes the button. Currently my .ajax()
call is being triggered by a jQuery .on('click')
event.
I'm getting lost and confused between learning to send the updates back via SSE and how to trigger the execution of tasker.php (and in some cases sending parameters to it, like .ajax()
enables me to do).
Any help clearing this out would be appreciated.
UPDATE #2: Found this example but as soon as the JavaScript loads it is triggered; I want to trigger execution when the button is clicked.
UPDATE #1: TO ADD SAMPLE CODE (Please excuse the formatting, I'm posting this from the mobile App) This is an abstract it of how I have it implemented right now:
<? php
$output ="";
/*dummy code*/
read_csv_file();
$output.= "Opened and read file<br/>"; //Step 1
parse_csv_file();
$output.= "CSV file successfully parsed"; //Step 2
delete_from_directory();
$output.= "CSV file successfully deleted"; //Step 3
insert_data_into_db();
$output.= "successfully inserted records into Database"; //Step 4
return $output;
?>
<div id="placeholder"></div>
<button id="button">Update</button>
//jQuery...
$('#button').on('click', function(){
.ajax({
url: 'tasker.php',
dataType: 'txt',
data: dataVariable,
success: function (data){
$('#placeholder').append(data);
});
});
//jQuery...