2017-09-25 54 views
0

标题说明了一切,我需要监视数据处理进度。例如,我为MySQL做了一些分块插入操作,并在每个块之后回显进度,如何在前端打印进度?我使用Dropzone.js和我现在的JS代码(简化版本):Dropzone.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 
}) 

回答

0

那么它的接缝,不是真的可能,我需要改变后端一点点。 所以我在后端创建了另一个方法监视当前进度,进度设置为会话,因此我需要2个AJAX cals,1个用于上传ant启动进程文件,另一个用于检查状态。

对于excample等待处理URL是http://example.com/import 对于状态检查http://example.com/import/status

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

{ 
    "status":"done" 
} 

我打电话检查状态funcion每隔1秒

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