Home › Forums › JavaScript › Java Script Set_Interval
- This topic is empty.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
October 5, 2015 at 9:24 pm #209284wolfgang1983Participant
On my script below I need to add $(‘#button-refresh’).trigger(‘click’);
So when the progress-bar reaches 100% it will trigger the id above.Because soon as I select a file to be uploaded it triggers the bootstrap progress bar to start. So what I am after is when the set_interval for progress bar has reached 100% then will trigger $(‘#button-refresh’).trigger(‘click’);
Any Suggestion On Best Placement.
<script type="text/javascript"> $('#button-upload').on('click', function() { $('#form-upload').remove(); <pre><code>$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" value="" /></form>'); $('#form-upload input[name=\'file\']').trigger('click'); if (typeof timer != 'undefined') { clearInterval(timer); } timer = setInterval(function() { if ($('#form-upload input[name=\'file\']').val() != '') { clearInterval(timer); setTimeout(function(){ $('.progress .progress-bar').each(function() { var me = $(this); var perc = me.attr("data-percentage"); var current_perc = 0; var progress = setInterval(function() { if (current_perc>=perc) { clearInterval(progress); } else { current_perc +=1; me.css('width', (current_perc)+'%'); } me.text((current_perc) +' %'); }, 50); }); },300); $.ajax({ url: 'admin/common/filemanager/upload/?directory=<?php echo $directory; ?>', type: 'post', dataType: 'json', data: new FormData($('#form-upload')[0]), cache: false, contentType: false, processData: false, beforeSend: function() { $('#button-upload i').replaceWith('<i class="fa fa-circle-o-notch fa-spin"></i>'); $('#button-upload').prop('disabled', true); }, complete: function() { $('#button-upload i').replaceWith('<i class="fa fa-upload"></i>'); $('#button-upload').prop('disabled', false); }, success: function(json) { if (json['error']) { alert(json['error']); } if (json['success']) { //alert(json['success']); //$('#button-refresh').trigger('click'); } }, error: function(xhr, ajaxOptions, thrownError) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } }, 500); }); </script>
-
AuthorPosts
Viewing 1 post (of 1 total)
- The forum ‘JavaScript’ is closed to new topics and replies.