Dinesh G
Dinesh G

Reputation: 1365

How to add variable to FormData in jquery?

Actually i am using following script to post my form

var formData = new FormData($("form#driver_information")[0]);
$.ajax({
    type: "POST",
    url: "/",
    data: formData, 
    success: function(data) {
    $("#page_message_box").html(data);
    },
    cache: false,
    contentType: false,
    processData: false
});

I need to pass some more variables along with form data

eg:

var formData = new FormData($("form#driver_information")[0]);
 $.ajax({
  type: "POST",
  url: "/",
  data: formData + "&con=delete",  
  success: function(data) {
  $("#page_message_box").html(data);
 },
   cache: false,
   contentType: false,
   processData: false
});

But it's not working.( data: formData + "&con=delete", ). Please help to solve this problem.

Upvotes: 7

Views: 11004

Answers (2)

rlarcombe
rlarcombe

Reputation: 2986

Try this:

formData.append('con', 'delete');

before the $.ajax call.

Then within that call you just need:

data: formData,

Upvotes: 7

Tdelang
Tdelang

Reputation: 1308

You can append data to FormData like this:

formData.append('con', 'delete');

Upvotes: 1

Related Questions