Jquery Dropzone dynamically change POST location

送分小仙女□ 提交于 2021-01-03 06:34:46

问题


I have an issue regarding Dropzone.js, I am looking to be able to change the post URL dynamically such as :

window.onload = function() {
  myDropzone = new Dropzone("#my-awesome-dropzone", {
    url: "upload_file.php"
  });
  myDropzone.on("complete", function(file) {
    myDropzone.removeFile(file);
  });
}

Where you see url: "upload_file.php", I would like to change this property as and when I need to, this to enable me to change the path that files are stored so i can do something similar to:

url: "upload_file.php?path=/path/to/folder/"

回答1:


The provided answers are incomplete without combining them. The one from the OP is the recommended way provided by the creator of dropzone.

Dropzone.options.myDropzone = {
  init: function() {
    this.on("processing", function(file) { // was processingfile
      this.options.url = "/some-other-url";
    });
  }
};

This can be seen in the Wiki and #94.

However, a more dynamic possibility is to use Dropzone.options.myDropzone.options.url. Obviously this is very extensive and can be pulled in a few different ways.

One being:

// assuming you have autodiscover off or you are using the whole body as a dropzone
Dropzone.options.myDropzone = new Dropzone(document.body, {
    url: '/default/url',
    ...
});

var myDropzone = Dropzone.options.myDropzone, url = "Your url";

function doSomething(dropzone, url){
    dropzone.options.url = url
}

doSomething(myDropzone, url)
console.log(myDrozone.options.url);

I currently prefer the second approach, but the first is obviously useful in its own ways.




回答2:


Sorted...

Dropzone.options.myDropzone = {
  init: function() {
    this.on("processingfile", function(file) {
      this.options.url = "/some-other-url";
    });
  }
};

from: https://github.com/enyo/dropzone/wiki/Set-URL-dynamically




回答3:


Just use

Dropzone.options.myDropzone.options.url = "Your url";


来源:https://stackoverflow.com/questions/27450429/jquery-dropzone-dynamically-change-post-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!