Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Ajax Progress - how to not inherit progress percentage on different ajax requests?
    primarykey
    data
    text
    <p>Hi i'm actually using this plugin <a href="https://github.com/englercj/jquery-ajax-progress/" rel="nofollow">https://github.com/englercj/jquery-ajax-progress/</a></p> <p>It simply adds a progress: statment to ajax request.</p> <p>It works great and my code looks like this:</p> <pre><code>var _min_width = 470; var _min_height = 330; var _which; var _fyle_type; var _file_name; var allowed_types = new Array('image/png','image/jpg','image/jpeg'); if (typeof(FileReader) === 'function'){ $('input[type="file"]').on('change', function(e) { _file_name = $(this).val(); var file = e.target.files[0]; if (!in_array(file.type,allowed_types) || file.length === 0){ notify("You must select a valid image file!",false,false); return; } if(file.size &gt; 3145728 /*3MB*/){ notify("&lt;?php echo lang('each-photo-1MB'); ?&gt;",false,false); return; } notify_destroy(); var reader = new FileReader(); reader.onload = fileOnload; reader.readAsDataURL(file); }); function fileOnload(e) { var img = document.createElement('img'); img.src = e.target.result; img.addEventListener('load', function() { if(img.width &lt; _min_width || img.height &lt; _min_height ){ notify("&lt;?php echo lang('each-photo-1MB'); ?&gt;",false,false); return; } //remove not-needed base64 data:pfff var clear_string = e.target.result.replace('data:image/jpeg;base64,','').replace('data:image/png;base64,',''); var _data; if(_which == 'photo_1'){ _data = {photo_1:clear_string}; }if(_which == 'photo_2'){ _data = {photo_2:clear_string}; }if(_which == 'photo_3'){ _data = {photo_3:clear_string}; }if(_which == 'photo_4'){ _data = {photo_4:clear_string}; } $.ajax({ type:'post', dataType:'text', data:_data, url:_config_base_url+'/upload/upload_photos', beforeSend:function(){ $('.'+_which+'_holder').fadeOut(0); $('.'+_which+'_progress').fadeIn(0); $('.'+_which+'_progress').addClass('progress-striped'); }, progress:function(e){ //make sure we can compute the length if(e.lengthComputable) { //calculate the percentage loaded var pct = (e.loaded / e.total) * 100; $('.'+_which+'_progress .bar').css({'width':pct+'%'}); $('.'+_which+'_progress .progress-opt span').text(pct.toFixed(0)); //console.log(pct); }else { console.warn('Content Length not reported!'); } }, success:function(){ alert(_file_name+' uploaded ok'); }, complete:function(){ $('.'+_which+'_progress .progress-opt span').text('100'); $('.'+_which+'_holder p').text(_file_name); $('.'+_which+'_progress .bar').css({'width':'100%'}); $('.'+_which+'_progress').delay(300).removeClass('progress-striped').fadeOut(0,function(){ $('.'+_which+'_holder').show(0); $('.'+_which+'_progress .bar').css({'width':'0'}); }); } }); }); } } </code></pre> <p>now the problem is when i set <code>text(pct.toFixed(0))</code> in the <code>progress:</code> ajax statment, i need to make <code>pct</code> "live" i mean, this code puts request progress in percentage , so you can see how much in percentage it takes the request to end up.</p> <blockquote> <p>The problem is if i launch 2 of these requests the pct gets shared for both requests so if <strong>request 1</strong> is on 40% <strong>progress (pct)</strong> then the <strong>request 2</strong> will <strong>inherit</strong> the same progress percentage(pct = 40%) from <strong>request 1</strong></p> </blockquote> <hr> <h2> to better explain i would like to launch many of this requests but to > keep progress percentage (<strong>var pct</strong>) unique for each request</h2>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload