from Uploading a file using jQuery and CodeIgniter (but page refresh)
@cbrandolino suggests I use the jQuery plugin to solve my problem. It worked well, except for one problem, the callback function is not fire, as I expected.
Here is my modified
++ Javascript ++ code
$('#send_button').live('click', function(){
var options = {
url: 'formHandle/add',
success: function(){
alert('something');
}
};
$('#new_entry_form').ajaxSubmit(options);
})
++ Controller ++
function add(){
$array = array(
'title' => $this->input->post('title'),
'description' => $this->input->post('description'),
'content' => $this->input->post('content'),
'start' => $this->input->post('start'),
'due' => $this->input->post('due'),
'price' => $this->input->post('price'),
'promotion_price' => $this->input->post('promotion_price'),
'website' => $this->input->post('website'),
'author' => $this->input->post('author'),
);
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = false;
$config['remove_spaces'] = true;
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
if($this->upload->do_upload('picture')){
$array['picture'] = $this->upload->file_name;
$this->load->model('entry_model');
$this->entry_model->insertEntry($array);
echo 'true';
}else{
echo 'false';
}
}
Downloading the file worked, the file was downloaded to a specific folder.
Data insertion worked, data was inserted into the database as expected.
The only problem I came across is the callback function.
Do you have an idea how to fix this? I need to show the result of data insertion.
:
return false .