问题
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