Reputation: 2206
I have develop ajax upload with upload library in coodeigniter.
This is the data that I grab with jquery :
var inputFile = $('input#file');
var filesToUpload = inputFile[0].files;
// make sure there is file(s) to upload
if (filesToUpload.length > 0) {
// provide the form data that would be sent to sever through ajax
var formData = new FormData();
for (var i = 0; i < filesToUpload.length; i++) {
var file = filesToUpload[i];
formData.append("file[]", file, file.name);
}
This is my ajax :
$.ajax({
url: "<?php echo base_url('surveyor/c_surveyor/add_file_image'); ?>",
type: 'post',
data: formData,
processData: false,
contentType: false,
success: function () {
$(":file").val('');
$(":text").val('');
$("#tableClean").find("tr:gt(0)").remove();
$("#tableReport").find("tr:gt(0)").remove();
$("#addRow").attr("disabled", false);
$("#addClean").attr("disabled", false);
$('#pilih_isotank').after('<div class="callout callout-success lead" id="div_error"><p id="pesan_error">Semua Data Berhasil Terupload</p></div>');
$('#div_error').fadeIn("fast");
$('#pesan_error').html(obj.Message);
$('#div_error').fadeOut(7000);
myArrays = [];
}
});
I have a problem with this, how to pass another data in $ajax ilike this :
data: formData, EIR_REF : $('#no_eir').val();
I try to acces this EIR_REF
like this on this url :
public function add_file_image(){
echo $this->input->post('EIR_REF');
}
It gives me nothing. How can I make it true ?
Upvotes: 0
Views: 331
Reputation: 98
formData.append will work as well. Just add the code below outside the loop before posting to server.
formData.append('EIR_REF', $('#no_eir').val());
Upvotes: 1
Reputation: 4739
You can pass the formdata in a separate field and the extra field can append as shown below. And in the serever side you can access accordingly. Try this:
data: {formData:formData, EIR_REF : $('#no_eir').val()};
Upvotes: 0