0

I have a form and it has text inputs and file input for upload an image. I tried to send values to my php page but i couldnt do it. Here is my ajax codes.

function sendval() {
  var form = $('#user_update_form')[0];
  var form_data = new FormData();

  $.ajax({
    type: 'POST',
    url: 'user_update.php',
    processData: false,
    data: form_data,
    success: function(msg) {
      $('#updtalert').html(msg);
    }
  });
}
31piy
  • 21,164
  • 6
  • 40
  • 57
Nevzat Uz
  • 17
  • 1
  • 8

2 Answers2

0

You should add from ajax inside this code

function sendval(){
    var form = $('#user_update_form')[0];
    var form_data = new FormData(this); 
    $.ajax({
        type:'POST',
        url:'user_update.php',
        processData: false,
        cache:false,
        contentType: false,
        data:form_data,
        success: function (msg) {
            $('#updtalert').html(msg);
        }
    });
}
Prabu T
  • 27
  • 3
  • thanks for your response. I just changed var form_data = new FormData(this); "this" to "form" and it worked. – Nevzat Uz Jun 22 '17 at 14:13
0

Try below code :

function sendval(){
    var form = $('#user_update_form')[0];
    var form_data = new FormData(form); 
    $.ajax({
        type:'POST',
        url:'user_update.php',
        processData: false,
        contentType:  false,
        data:form_data,
        success: function (msg) {
            $('#updtalert').html(msg);
        }
    });
}
Pankaj Makwana
  • 2,964
  • 6
  • 28
  • 45