jQuery file upload doesn't submit extra parameters

ε祈祈猫儿з 提交于 2020-01-02 06:12:25

问题


I need to use the formData parameter available in the jQuery File Upload control to send additional data to the server on submit. The default implementation for formData is to invoke a function that grabs all controls in the form and serializes them to an array (using the jQuery serializeArray() method).

I have controls in my form, but when the file is uploaded, I am not getting any additional data. When I inspect via Fiddler, there is nothing in the request that shows these form fields are being submitted.

Is there something additional that needs to be done to get these to submit?

Btw, these two links discuss formData...

https://github.com/blueimp/jQuery-File-Upload/wiki/Submit-files-asynchronously https://github.com/blueimp/jQuery-File-Upload/wiki/Options ...for this one search the page for formData.

For what its worth, the multipart option is set to true.


回答1:


I also needed to pass an extra parameter and here is what i used :

$('#fileupload').fileupload({
    formData: {
                    param1: 'test'
                    ,param2: "value2"
                    ,param3: "yasseshaikh"
              }
});

The formData option can be used to set additional form data programmatically.




回答2:


Complete code (I modified the answer provided by Yasser)

Add these code into jquery.fileupload.js

submit: function (e, data) {

    $('#fileupload').fileupload({
          formData: {
                 param1: 'test'
                ,param2: "value2"
                ,param3: "yasseshaikh"
          }
    });
},



回答3:


If the blueimp plugin isn't a requirement I would really recommend the jquery malsup form.

You can use a regular multipart form and just create a regular file input field along with other input fields of your own choice and everything is submitted as usual.

Reference: http://www.malsup.com/jquery/form/

Code sample:

$('#myForm2').submit(function() { 
    $(this).ajaxSubmit(options); 
    return false; 
}); 



回答4:


You have to bind Your data to fileupload. Look at this question
Blueimp jQuery file upload, passing extra form data



来源:https://stackoverflow.com/questions/15647503/jquery-file-upload-doesnt-submit-extra-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!