2

I want to send id also with formdata ! How can i do this please edit my code so that i can understand easily.

$(document).ready(function() {
  $("#profile_photo_form").on('submit', (function(e) {
    e.preventDefault();
    var id = $("#update").attr("update");

    $.ajax({
      url: "/php/profile_photo.php",
      type: "POST",
      data: new FormData(this),
      beforeSend: function() {},
      contentType: false,
      processData: false,
      success: function(data) {
        alert(data);
        $("#toggle").load('/all_employees.html');
      },
      error: function() {}
    });
  }));
});
Pedram
  • 15,766
  • 10
  • 44
  • 73

2 Answers2

2

You just need to append id in FormData

$(document).ready(function() {
  $("#profile_photo_form").on('submit', (function(e) {
    e.preventDefault();
    var id = $("#update").attr("update");
    var data = new FormData(this);
    data.append('id',id);
    $.ajax({
      url: "/php/profile_photo.php",
      type: "POST",
      data: data,
      beforeSend: function() {},
      contentType: false,
      processData: false,
      success: function(data) {
        alert(data);
        $("#toggle").load('/all_employees.html');
      },
      error: function() {}
    });
  }));
});
freelancer
  • 1,174
  • 5
  • 12
1

You need to use append method of FormData to set your additional keys.

var data = new FormData();
data.append(‘id’,id);
DeadCoderz
  • 237
  • 3
  • 8