Download jQuery file by specifying FormData

I am working on the following jQuery download plugin:

https://github.com/blueimp/jQuery-File-Upload/wiki/Options

I need to specify additional additional data, which says that there is an option, but I get a JS error "Uncaught SyntaxError: Unexpected identifier", and there are no examples of FormData, which makes work difficult.

Here is what I have:

$(function () {
    $('.upload').fileUploadUI({
        uploadTable: $('.upload_files'),
        downloadTable: $('.download_files'),
        buildUploadRow: function (files, index) {
            var file = files[index];
            return $(
                '<tr>' +
                '<td>' + file.name + '<\/td>' +
                '<td class="file_upload_progress"><div><\/div><\/td>' +
                '<td class="file_upload_cancel">' +
                '<div class="ui-state-default ui-corner-all ui-state-hover" title="Cancel">' +
                '<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
                '<\/div>' +
                '<\/td>' +
                '<\/tr>'
            );
        },
        buildDownloadRow: function (file) {
            return $(
                '<tr><td>' + file.name + ' ' + file.type + ' ' + file.size + '<\/td><\/tr>'
            );
        },
  formData: 
   [
     {
       name: '_http_accept'
       value: 'application/javascript'
     },
     {
       name: '<%= session_key_name %>'
       value: encodeURIComponent('<%= u cookies[session_key_name] %>'),
     },
     {
       name: 'authenticity_token'
       value: encodeURIComponent('<%= u form_authenticity_token %>')
     }
   ]
    });
});
+3
source share
1 answer

You do not have commas in the right places in formData, I think you want this to be like this:

formData: [
    {
        name: '_http_accept',
        value: 'application/javascript'   
    }, {
        name: '<%= session_key_name %>',
        value: encodeURIComponent('<%= u cookies[session_key_name] %>')    
    }, {
        name: 'authenticity_token',
        value: encodeURIComponent('<%= u form_authenticity_token %>')  
    }
]

Note that after parts name: ...there are commas, but not parts value: ....

, , encodeURIComponent() escaping/encoding <%= u ... URI. , , , , - , , ( , JavaScript ERB):

value: '<%= cookies[session_key_name].gsub(/'/, "\'") %>'

, POST, URL- .

, JavaScript, , '</td>', '<\/td>'.

jQuery-File, , , ( !).

+7
source

Source: https://habr.com/ru/post/1787557/