I can't download file.I am trying to download file from server through Ajax. I got success response in Ajax data and also file in response but file was not download what i do and how to fix this issue. The file reads successfully and also sever path get proper. Please help me.
This one is java script when i call function and get response throw ajax
<script type="text/javascript">
function push_file(files)
{
$.ajax
({
type: "post",
url: "<?php echo base_url(); ?>Appointment/download_files/",
data: "files=" + files,
success: function(data)
{
alert('ok' + data);
}
});
}
</script>
PHP code and here i want to download file here and
foreach($results as $row){
$r_id = $row->id;
<td><h5><a onclick="push_file(<?php echo $r_id;?>)"> Download </a></hs><t>
}
Controller Ajax and PHP perform perfectly and read file but its not download
public function download_files() {
//$this->load->view ( 'ajax/download' );
if($_POST)
{
$base = base_url();
$id = $_POST['files'];
$query = $this->db->query("select userfile from patient_report_file where id='".$id."'");
$result = $query ->row();
$name = $result->userfile;
echo $path = $base."Admin/uploads/patient_report/".$name;
force_download($path, NULL);
}
}
How can I download the file.