J'essaie d'insérer les données d'un formulaire via Ajax et Codeigniter mais je ne parviens pas à insérer les données, obtenant l'erreur 'You did not select a file to upload'. Je rencontre des problèmes avec les téléchargements de fichiers. Je n'ai aucune idée de la façon de passer les données du fichier d'entrée par jQuery ajax.
Voici mon code jQuery :
$('#saveAddress').click(function(event){
event.preventDefault();
var add = $('#address').val();
var city = $('#city').val();
var state = $('#sate').val();
var district = $('#district').val();
var pcode = $('#pincode').val();
var pType = $('#proofType').val();
var aProof = new FormData($('#addressProof'));
if(add != "" && city != "" && state != "" && district != "" && pcode != "" && pType != "" && aProof != ""){
$.ajax({
type:"POST",
url:"<?php echo base_url();?>index.php/MyApp/addressDetails",
data:{address:add,city:city,state:state,district:district,pincode:pcode,proofType:pType,addressProof:aProof},
contentType: false,
processData: false,
beforeSend: function() {
jQuery('#pbo-loader').css('display','block');
},
success:function(response){
console.log(response);
},
error: function(jqXHR) {
console.log(jqXHR);
},
complete:function(){
jQuery('#pbo-loader').css('display','none');
}
});
}
});
code contrôleur :
public function addressDetails(){
if($this->session->userdata('currently_logged_in')){
$pbonum = $this->session->userdata('pbonum');
if(isset($_POST)){
$noti['add'] = $this->input->post('address');
$noti['img'] = $this->input->post('addressProof');
$thumb = 'addressProof_'.$pbonum;
$config['file_name'] = $thumb;
$config['upload_path'] = 'uploads/kyc/address/';
$config['allowed_types'] = 'gif|jpg|png|pdf|doc';
$config['max_size'] = 2000;
$this->load->library('upload');
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('addressProof'))
{
$noti['error'] = array('error' => $this->upload->display_errors());
}
else
{
$data = array('upload_data' => $this->upload->data());
$thumb = $data['file_name'];
$res = $this->CustomerModel->updateAddressDetails($thumb);
if($res == 1){
$noti['status'] = "success";
}
else{
$noti['status'] = "failed";
}
}
print_r($noti);
}
}
else{
$this->load->view('templates/header');
$this->load->view('signin');
$this->load->view('templates/footer');
}
}