Clem
Clem

Reputation: 11824

Additional data in ajax POST when sending file

My question is, if there exist any solution for sending some kind of data(for an example string), beside formData? For an example, to add something to data parameter.

Current data parameter looks like this:

data: form,

I wish to send additional string, something like:

data: {someValue: 'something', file: form}

Is possible to achieve this somehow, because I need to send some string also. (I do not wish to add additional parameter to url like "?site=example").

Current code:

variables.ajaxVar = $.ajax({
    url: '../../bh-api/?action=archiveUpload',
    type: 'POST',
    xhr: function() {
        var myXhr = $.ajaxSettings.xhr();
        if(myXhr.upload){
            myXhr.upload.onprogress = progress;
        }
        return myXhr;
    },
    success: function (res) {
        console.log(res)
    },
    data: form,
    cache: false,
    contentType: false,
    processData: false
});

Upvotes: 0

Views: 1054

Answers (2)

BenM
BenM

Reputation: 4278

May not be what you're looking for but you can add an <input type="hidden"> field to your form and store your data there?

Upvotes: 0

Musa
Musa

Reputation: 97672

You can append parameters to the form data object

form.append('someValue', 'something');

Upvotes: 1

Related Questions