Hi guys,
CI Version 3
I am having a very very hard time finding the bug.
Code:
<script>
$(document).delegate("#btn_upload", "click", function(event){
var fd = new FormData();
var files = $('#file')[0].files;
var product_id=$("#product_id").val();
// Check file selected or not
if(files.length > 0 ){
fd.append('file',files[0]);
fd.append('product_id',product_id);
//alert(fd);
$.ajax({
url: '<?php echo base_url(); ?>products/photo_upload',
type: 'POST',
data: fd,
processData: false,
contentType: false,
beforeSend:function(){
$("#loader_upload").show();
},
complete:function(){
$("#loader_upload").hide();
},
success:function(response){
$('#alert_upload').html(response);
//if file upload is success. then write to db//
if(response!=""){
var dataString = 'product_id='+ product_id
+ '&file_name=' + response;
//alert(dataString);
$.ajax({
url: '<?php echo base_url(); ?>products/update_photo_path_to_db',
type: 'POST',
data: dataString,
contentType: false,
processData: false,
beforeSend:function(){
$("#loader_upload").show();
},
complete:function(){
$("#loader_upload").hide();
},
success: function(response){
console.log(response);
$('#alert_upload').html(response);
if(response=="1"){
//db update success
}else{
alert('Opps. coult not update database.Please try again');
return false;
}
},
});
}else{
alert('Photo upload error.');
return false;
}
},
});
}else{
alert("Please select a file.");
}
});
</script>
Console
Chrome inspect > network > headers
product_id=22&file_name=/home/likesril/ibfresh.antlerweb.xyz/assets/uploads/22_user2-160x160.jpg
product_id=22&file_name=/home/likesril/ibfresh.antlerweb.xyz/assets/uploads/22_user2-160x160.jpg
Problem is : controller shows NULL
array(0) { } UPDATE `products` SET `photo` = NULL WHERE `product_id` IS NULL
Controller
public function update_photo_path_to_db() {
Code:
var_dump($this->input->post());
}
array(0) { }
I am having a hard time with this editor. you might see the post jammed. i have no idea how to fix.