这个简单的ajax调用在Chrome,FF,Safari中运行良好:
function downloadEntryReport() {
var data_range = document.getElementById("daterange").value;
var ajax_url = "ajaxcalls/download_entry_report/"+data_range;
$.ajax({
cache: false,
type: 'POST',
url: ajax_url,
dataType: 'text',
error: function(){
alert('Error loading document');
return false;
},
success: function(data) {
document.location.href = "ajaxcalls/download_entry_report/"+data_range;
}
});
}
除了IE(在9.0.8中测试)。 IE打开URL(ajaxcalls / download_entry_report / given_date_range),当然会返回404错误。在IE中是否有关于此问题的黑客攻击或我错过了什么? 感谢您的帮助!
这里是被调用的PHP函数:
function download_entry_report($data_range) {
$date_range_array = explode("%20::%20", $data_range);
$start_date = $date_range_array[0];
$end_date = $date_range_array[1];
$query = $this->db->query("SELECT * FROM tbl_name WHERE created_by = '".$this->session->userdata('email')."' AND DATE_FORMAT(created_date, '%Y-%m-%d') BETWEEN '".$start_date."' AND '".$end_date."' ");
$results = $query->result_array();
echo $this->download_csv_results($results, 'entry_report.csv');
exit();
}
和另一个下载csv文件的功能:
function download_csv_results($results, $name = NULL)
{
if( ! $name)
{
$name = md5(uniqid() . microtime(TRUE) . mt_rand()). '.csv';
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename='. $name);
header('Pragma: no-cache');
header("Expires: 0");
$outstream = fopen("php://output", "w");
foreach($results as $result)
{
fputcsv($outstream, $result);
}
fclose($outstream);
}