LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 267 forks source link

Passing dynamic custom data to server #120

Closed ajeetksingh closed 8 years ago

ajeetksingh commented 9 years ago

How can one transfer the dynamic data to the server. How can I send an value chosen from the dropdown list along with the file:

data: {"test": $("#testValue").val()}

It's working fine for static data passed like this:

data: {"test": "1"}

PS: Assume that I have got an hidden input element whose value has already been set to the data from the dropdown list.

LPology commented 8 years ago

You need to use the the setData() method inside of the onSubmit() callback function. For example:

var uploader = new ss.SimpleUpload({
    button: someBtn,
    url: '/uploadUrl',

    // Other options...

    onSubmit: function() {
            var self = this;

            self.setData({
                test: $("#testValue").val()
            });
        }
});

The setData() method sets the value of the data option. It accepts an object.

Setting the data option during onSubmit() allows you to grab the value of an input field at the time the upload was submitted.