I want to show progress status for my ajax call to client page and that too dynamically as in a real time progress of the task. The task is big and does a lot of processing so its better to display %age status to the waiting user.
I am using JQuery Progress Bar UI for the same but its currently showing static progress. The progress bar gets completed but actually the request is still being processed.
How could I change my code to retrieve dynamic status of the task and show it in the progress? Below is my code:
The progress function:
function progress() {
var progressbar = $( "#progressbar" ),
progressLabel = $( ".progress-label" );
progressbar.progressbar({
value: false,
change: function() {
progressLabel.text( progressbar.progressbar( "value" ) + "%" );
},
complete: function() {
progressLabel.text( "Complete!" );
}
});
function progress() {
var val = progressbar.progressbar( "value" ) || 0;
progressbar.progressbar( "value", val + 2 );
if ( val < 99 ) {
setTimeout( progress, 80 );
}
}
setTimeout( progress, 2000 );
}
The Ajax call:
function loadAjax() {
progress();
var urlValue = document.getElementById("url").value;
$.ajax({
type : "GET",
url : "/prismweb/testSinglePage?url="+urlValue,
success : function(response) {
$("#progressbar").hide();
//more code goes here....
}
});
}
HTML:
<div id="url_bar"><input id="url" type="text" placeholder="Enter the page URL...." size="10"></div>
<div id="progressbar"><div class="progress-label">Loading...</div></div>