How to add a variable to FormData in jquery?

I actually use the 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 the 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 does not work. ( data: formData + "&con=delete",). Please help solve this problem.

+4
source share
2 answers

Try the following:

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

before calling $ .ajax.

Then, as part of this call, you just need to:

data: formData,
+1
source

You can add data to FormData as follows:

formData.append('con', 'delete');
+1
source

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


All Articles