I am using this api for file upload and need to pass some data dynamically when onFilePrepare event is fired but it is not sending that data to url. Please suggest as I have to add 1 new data param b from onFilePrepare event, which is not avaiable during initially since fileapi is being called from nested ajax setup

https://github.com/RubaXa/jquery.fileapi

CODE :

 $('#multiupload').fileapi({
                   url: "url",
                   data: ({'a':'A'}), 
                   clearOnComplete: true,
                   multiple: true,
                   elements: {                    
                      ctrl: { upload: '.js-upload' },
                      emptyQueue: { hide: '.js-upload' },
                      list: '.js-files',
                      name: '.js-name',
                      size: '.js-size',
                      file: {
                         tpl: '.js-file-tpl',
                         preview: {
                            el: '.b-thumb__preview',
                            width: 80,
                            height: 80
                         },
                         upload: { show: '.progress', hide: '.b-thumb__rotate' },
                         complete: { hide: '.progress' },
                         progress: '.progress .bar'
                      }
                   },
                   onFilePrepare : function(evt,ui) {

                       //pass more data dynamically
                       ui.xhr.options.data = { 'a':'A','b':'B'};
                       console.log(ui.xhr.options);
                   },
                   onComplete : function (evt, ui) {

                       //read ajax data returned
                       var data = JSON.parse(ui.xhr.response);
                       console.log(ui.xhr.options);

                   }                       

            }); 
有帮助吗?

解决方案

With latest Rubaxa library, this works by doing as below - Thanks to rubaXa for helping in git

Changes in onFilePrepare

 $('#multiupload').fileapi({
                   url: "url",
                   data: ({'a':'A'}), 
                   clearOnComplete: true,
                   multiple: true,
                   elements: {                    
                      ctrl: { upload: '.js-upload' },
                      emptyQueue: { hide: '.js-upload' },
                      list: '.js-files',
                      name: '.js-name',
                      size: '.js-size',
                      file: {
                         tpl: '.js-file-tpl',
                         preview: {
                            el: '.b-thumb__preview',
                            width: 80,
                            height: 80
                         },
                         upload: { show: '.progress', hide: '.b-thumb__rotate' },
                         complete: { hide: '.progress' },
                         progress: '.progress .bar'
                      }
                   },
                   onFilePrepare : function(evt,ui) {

                       //pass more data dynamically
                       ui.options.data.b = 'B';
                   },
                   onComplete : function (evt, ui) {

                       //read ajax data returned
                       var data = JSON.parse(ui.xhr.response);
                       console.log(ui.xhr.options);

                   }                       

            });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top