【问题标题】:How can I use Dropzone.js in my own function如何在我自己的函数中使用 Dropzone.js
【发布时间】:2019-05-27 04:08:57
【问题描述】:

我在将 Dropzone.js 与我自己的 ajax 函数集成时遇到了困难,我不知道应该怎么做才能在我的 ajax 函数中使用 dropzone。

这是我自己的ajax功能代码:

function _ajaxForm(formHandler){
var action = $(formHandler).attr('action');
$.post(action, $(formHandler).serialize(), function(data){
    // I want to submit my fields and my form upload using this function
}, 'json');}

【问题讨论】:

  • 你能详细说明你想要做什么吗?
  • 如何在这个函数中集成 dropzone

标签: jquery dropzone.js


【解决方案1】:

您只需要相应地配置您的放置区。

使用sending 事件,您可以执行以下操作:

Dropzone.options.myAwesomeDropzone = {
  // Some default configurations
  paramName: "file", // The name that will be used to transfer the file
  maxFilesize: 2, // MB
  // Additional configurations needed for your ajax call
  url: "insertyoururlhere",
  init: function () {
      this.on("error", function (error, message) {
        //do something to handle the error
      });
      this.on("success", function (success, response) {
        //do something
      });
      this.on("sending", function (file, xhr, formData) {
        //add any form data that you would have in your ajax function eg:
        //formData.append("id", 123);
      });
      this.on("complete", function () {
        this.removeAllFiles(true);
        //do something
      });
    }
});

请参阅 thisthisthis 答案,这也可能有所帮助。

【讨论】:

    猜你喜欢
    • 2016-06-20
    • 2013-01-20
    • 1970-01-01
    • 2018-05-28
    • 1970-01-01
    • 2016-09-09
    • 2021-08-13
    • 1970-01-01
    • 2021-08-13
    相关资源
    最近更新 更多