【问题标题】:Dropzone.js proccess file after upload and monitor progressDropzone.js 处理文件上传后监控进度
【发布时间】:2017-09-25 15:01:41
【问题描述】:

标题说明了一切,我需要监控数据处理进度。例如,我对 MySQL 进行了一些分块插入并在每个块之后回显进度,如何在前端打印进度?我正在使用 Dropzone.js,我当前的 JS 代码是(简化版):

Dropzone.options.importdropzone = {

                init: function() {

                    // I need something like
                    this.on("backendProccessing",function(response){
                      return response
                    })

                    this.on("success", function(file, response) {
                        // Success only return after backend finish process
                    })

                }
            };

也试过(不起作用,没有返回,只有成功):

this.on('xhr',function(){

  // get the native XmlHttpRequest object
  var xhr = $.ajaxSettings.xhr() ;
  // set the onprogress event handler
  xhr.onprogress = function(evt){ console.log('Doing') } ;
  // set the onload event handler
  xhr.onload = function(){ console.log('DONE!') } ;
  // return the customized object
  return xhr ;

});

所以我需要这样的东西:

this.on("backendProccessing",function(response){
  return response
})

【问题讨论】:

    标签: jquery ajax dropzone.js


    【解决方案1】:

    嗯,这是不可能的接缝,我需要稍微改变后端。 所以我在后端创建了另一种方法来监控当前进度,进度设置为会话,所以我需要 2 个 AJAX cals,1 个用于上传 ant start proccessing 文件,另一个用于检查状态。

    例如处理 URL 是 http://example.com/import 状态检查http://example.com/import/status

    我可以检查状态直到它返回特定的值,比如

    {
      "status":"done"
    }
    

    我每隔 1 秒调用一次检查状态函数

    this.on('sending',function() {
      // calling another ajax here every x sec.
    }
    

    【讨论】:

      猜你喜欢
      • 2011-09-11
      • 1970-01-01
      • 2014-07-31
      • 2015-09-02
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多