javascript - How to make polling script using javasctipt and ajax -
i have script runs long conversion php script , progress polling script. after looking @ several posts subject found should possible utilize async ajax calls combined timeout javascript create construction poll progress regularly , update page percentile number. see code below
function startexcelconversion(excelname){ var poll = function(){ settimeout(function(){ $.ajax({ url: "../include/ajax/ajax.php?action=poll_progress", success: function(data){ //update progress bar // show progress console.log('progresser: '+data); $("#progress").val(data); //setup next poll recursively poll(); }, complete: function( jqxhr, textstatus ){ //update progress bar // show progress console.log(textstatus); }, datatype: "json" }); }, 3000); }; poll(); //show loading image console.log('starting conversion'); $('#progress').val("excel openen..."); $('#main').prepend('<img id="loading" src="../include/image/load.gif">'); $("#loading").show(); $.ajax({ url: '../import/import_main.php?clean&action=importexcel&excelname='+excelname, success: function(data) { console.log(data); $("#main").html(data) $('#loading').hide(); } }); homecoming false;
}
the first block launches script runs while (excel reading , conversion).this script updates database table every 10 rows set progress. sec block (from start polling onwards0 should launch php script reads progress db field , echo can update input field percentile. polling script not called during runtime of first php script (import_main.php). tried $.post , $.get calls (which should $.ajax asynchronous default). tried setinterval did not work , not recommended due timing problems. missing obvious here or setting in php missing?
thnx in advance
i seek define poll @ top of script, like:
var poll = function(){ settimeout(function(){ $.ajax({ url: "../include/ajax/ajax.php?action=poll_progress", success: function(data){ //update progress bar // show progress console.log('progresser: '+data); $("#progress").val(data); //setup next poll recursively poll(); }, datatype: "json" }); }, 3000); });
and phone call it, like, poll()
, after ajax call. see if helps. right now, have anonymous function after ajax call, tries phone call poll(); in success callback, isn't going defined.
javascript php ajax progress polling
No comments:
Post a Comment