I want to update a progress bar (bootstrap) while a PHP page is processing from an AJAX GET request.
Currently the progress bar updates AFTER the AJAX request is 100% complete. The pages have a lot more content than what's listed, but this is the basics on what needs to get functional.
Main PHP Page
<html><head>
<script type="text/javascript">
function updateBar(i)
{
$('#updateBar').html('<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: '+i+'%;">'+i+'</div>');
}
</script>
</head>
<body>
<?
echo "<button class='btn btn-success' id='button'>Process</button>";
echo "<div class='progress' id='updateBar'>Loading...</div>";
echo "<div id='update'></div>";
?>
<script>
$(document).ready(function () {
$("#button").click(function(){
$("#update").text("Loading...");
$.ajax({
type: "GET",
url: "ajaxPHP",
success: function(data){
$("#update").html(data);
},
error: function(xhr, status, error) {
alert(xhr.responseText);
}
});
});
});
</script>
AJAX PHP Page (ajaxPHP):
$max=85;
for($i=0;$i>=$max;$i++){
// HERE ARE A BUNCH OF CURL CALLS AND SERVER SIDE PROCESSING, TAKING ABOUT 30 SECONDS PER LOOP
?>
<script>
var num = "<?php echo $i; ?>";
var max = "<?php echo $max; ?>";
var i = num/max;
updateBar(i);
</script>
<?
}