I want to upload file along with other field data but all other data will posted but how to post file through ajax to controller.
my view file
<form method="post"action=""id="meetingform"enctype="multipart/form-data" >
<label for="inputEmail4">Meeting Date</label>
<input type="text" id="date" name="meetingdate">
<label for="inputEmail2" >Subject</label>
<input type="text" id="subjectt" name="subject" placeholder="Subject">
<input type="hidden" name="meetingevent" value="Meeting"/>
<label for="inputEmail2" >Venue</label>
<input type="text" id="venuee" name="venue" placeholder="Venue" >
<label for="inputEmail2" >Description</label>
<textarea name="description" id="desc" placeholder="Description" >
</textarea>
<label for="inputEmail2" >MOM</label>
<input type="text" id="momm" name="mom" placeholder="MOM" >
<input type="file" name="photo" id="photo">
<input type="file" name="document" id="documents">
<button type="button" id="submit"> </button>
</form>
my script is
<script>
$(document).ready(function () {
$("#submit").click(function (e) {
$.ajax({
url: '<?php echo site_url() ?>admin/meeting_form',
type: 'POST',
fileElementId :'photos',
data: $("#meetingform").serialize(),
success: function () {
$('#msg').html('<span style="color:green;align:center;">Data
Posted.</span>');
$('#date').val('');
$('#subjectt').val('');
$('#venuee').val('');
$('#desc').val('');
$('#momm').val('');
$('#photo').val('');
$("#msg").delay(3000).fadeOut();
},
error: function () {
$('#msg').html('<span style="color:red;">Data didnot post .
</span>');
}
});
});
});
</script>
my controller
public function meeting_form() {
$session_data = $this->session->userdata('admin_logged_in');
$id = $session_data['id'];
if ($session_data) {
$this->form_validation->set_rules('meetingdate', 'Meeting Date',
'required');
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('venue', 'Venue', 'required');
$this->form_validation->set_rules('description', 'Description','required');
$this->form_validation->set_rules('mom', 'MOM', 'required');
if ($this->form_validation->run() == false)
{
$this->load->view('project_monnetering');
}
else
{
$data = array('event_date' => date('y-m-d', strtotime($this-
>input->post('meetingdate'))), 'event_type' => $this->input-
>post('meetingevent'), 'user_id' => $id,
'post_description' => $this->input->post('description'));
$last_id = $this->admin_model->insert_event_master($data);
$data1 = array('meeting_date' => date('y-m-d', strtotime($this-
>input->post('meetingdate'))), 'event_id' => $last_id, 'subject'
=> $this->input->post('subject'),
'venue' => $this->input->post('venue'), 'brief_desc' =>
$this->input->post('description'), 'mom' => $this->input-
>post('mom'));
$this->admin_model->insert_meeting_details($data1);
redirect('admin/project_monnetering', 'refresh');
}
} else {
$this->load->view('login');
}
}
How can i upload file along with other filed data here?