简体   繁体   中英

Dropzone JS - Redirect after all files have uploaded

I have the below dropzone JS form which uploads files as It should.

<form action="upload.php" class="dropzone" id="dropzone" >
<div class="dz-message needsclick" style="margin-top:-20px">
<i data-feather="upload-cloud" style='margin-top:4px'></i>
<h4 style='font-weight:100'>Drag image here or click to upload</h4>
</div>
</form>

I am trying to get the page to redirect to another page when ALL uploads are completed. From a search, I found the below script, however it doesn't seem to do anything

<script>
dropzone.on("success", function(file, responseText) {
  window.location.href = ("Uploaded.php")
});
</script>

EDITED: use the following event ' queuecomplete ' instead of 'success'

Documentation: https://www.dropzonejs.com/#events

At first, make sure your back-end is functioning properly (so the upload went OK). If so, success event should be fired once the file(s) have been uploaded.

Try with the below code in your script:

// Need disabling autoDiscover, otherwise Dropzone will try to attach twice.
Dropzone.autoDiscover = false;
// or disable for specific dropzone:
// Dropzone.options.myDropzone = false;

$(function() {
  // initialize the dropzone
  var myDropzone = new Dropzone("#dropzone");

  // change the location according to your preference
  // use queuecomplete instead of success event
  myDropzone.on("queuecomplete", function(file) {
    window.location.href="test.php"
  });
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM