jquery - combine javascript progress bar with another javascript -
i have javascript progressbar:
<script> $(function() { $( "#progressbar" ).progressbar({ value: 37 }); }); </script>
i have javascript automaticaly gets value file:
<script> var time = 0; setinterval(function() { $.ajax({ type: "post", data: {time : time}, url: "fileupdate.php", success: function (data) { var result = $.parsejson(data) if (result.content) { $('#file_content') .html(result.content); } time = result.time; } }); }, 1000); </script>
how can add js progress bar script value progress bar can automaticaly update?
thanks in advance.
you calling request every second.. want? stack request if not finished on , over..
what should probally do, per a.wolff's suggestion call function every time ajax call complete.. see code below:
see blog: http://www.dave-bond.com/blog/2010/01/jquery-ajax-progress-hmtl5/
function doajaxcall(){ $.ajax({ xhr: function(){ var xhr = new window.xmlhttprequest(); //upload progress xhr.upload.addeventlistener("progress", function(evt){ if (evt.lengthcomputable) { var percentcomplete = evt.loaded / evt.total; //do upload progress console.log(percentcomplete); } }, false); //download progress xhr.addeventlistener("progress", function(evt){ if (evt.lengthcomputable) { var percentcomplete = evt.loaded / evt.total; //do download progress console.log(percentcomplete); } }, false); return xhr; }, type: 'post', url: "/", data: {}, success: function(data){ doajaxcall(); //this call function again if call successful. } }); }
Comments
Post a Comment