0

my jquery is

$(document).on("click", ".addthisone", function (e) {
    var file_data = $(this).parent().parent().parent().find('input[type=file]').prop("files")[0];
    console.log(file_data);
    var form_data = new FormData();
    form_data.append("file", file_data);
    $.ajax({
        url: "<?php echo base_url('action/addimage');?>",
        //dataType: 'script',
        //cache: false,
        contentType: false,
        processData: false,
        data: form_data,
        type: 'post',
        success: function (d) {
            console.log(d);
        }

    })
    e.stopPropagation();
});

console.log() is displaying file data correctly but the problem is that it is not appending the file to formData(), nor i am able to var_dump() the $_post after submiting the form. on the controller action it show the empty array please help me out

CoderPi
  • 12,985
  • 4
  • 34
  • 62
Waqar Haider
  • 929
  • 10
  • 33

2 Answers2

1

Can you please use serialize function instant of FormData ?

Suman Biswas
  • 853
  • 10
  • 19
  • how would i know that the formData has accurately appended the file data in console, bcz when i log the form data in console it is showing me the form data and there are so many function so i can't see weather the file is appended to form or not – Waqar Haider Dec 01 '15 at 12:21
  • console.log($(formData).serialize()); – Waqar Haider Dec 01 '15 at 12:30
0

use $_FILES to get the uploaded files!!

AldoZumaran
  • 547
  • 5
  • 23