I'm creating a list with a set of checkboxes similar to the Trello tool, the data is extracted from the MySql database.
When the user selects one of the checkboxes to mark the activity as completed, I use an XMLHttpRequest request to make the asynchronous call of the php route and edit the task status to "completed" in the database. (Thus avoiding page refresh).
Also, I have a bootstrap progress bar that counts the number of rows in the table according to status "completed", "pending" and "total", and I use this data to populate the progress bar dynamically.
However, this bar is only updated when I enter the page or refresh it, I would like it to be updated along with the XMLHttpRequest request that is triggered every time the checkbox undergoes any change.
My question is: Is there any way to fill in the bar progress information according to XMLHttpRequest requests?
//CODE RESPONSIBLE FOR MAKING THE ASYNCHRONOUS REQUEST TO EDIT THE STATUS OF THE CHECKBOX IN THE DATABASE
function checkRealizado(url) {
let checkRealizado = new XMLHttpRequest();
checkRealizado.open('POST', url)
checkRealizado.onreadystatechange = () => {
if(checkRealizado.readyState == 4 && checkRealizado.status == 200) {
}
}
checkRealizado.send()
}
//CHECKBOX RESPONSIBLE FOR ACTIVATING THE XMLHTTPREQUEST FUNCTION
<label class="marcarConcluido" id="marcarConcluido" for="chkPassport">
<input onclick="checkRealizado('/tarefa?acao=checkRealizado&id='+<?= $checklist->id //DATA EXTRACTED FROM THE DATABASE, ALL OK HERE ?>)" class="form-check-input" id="chkPassport" style="margin-right: 8px" type="checkbox">
<?= $checklist->checklist //DATA EXTRACTED FROM THE DATABASE, ALL OK HERE ?>
</label>
//HTML CODE OF MY PROGRESS BAR
<div id="progressBar" class="progress text-muted" style="height: 6px;" role="progressbar" aria-label="Basic example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="<?= $this->view->getLinhasCheck ?>">
<progress class="text-muted progress-bar w-100" style="background-color: #fff; height: 6px;" value="<?= $this->view->getLinhasCheckRealizada ?>" max="<?= $this->view->getLinhasCheck ?>"></progress>
</div>
/// $this->view->getLinhasCheckRealizada This variable is responsible for filling in the data according to the number of rows in the database table, everything working so far
// $this->view->getLinhasCheck This variable is responsible for filling in the data according to the number of rows in the database table, everything working so