我有一个简单的联系表格下载excel文件。主要问题发生,当ajax加载。我想下载excel文件,然后重定向用户到下一页..下面是我的代码与伪数据。
Ajax代码..
$.ajax({ type: "POST",url: "/site/ajaxexcel.PHP",data: {'value':'send'},cache: false,success: function(html){ location.href = '<?PHP echo base_url()."/site/welcome.PHP" ?>'; } });
<?PHP $content= '<html xmlns:x="urn:schemas-microsoft-com:office:excel"> <head> <!--[if gte mso 9]> <xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name>Sheet 1</x:Name> <x:WorksheetOptions> <x:Print> <x:ValidPrinterInfo/> </x:Print> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> </x:ExcelWorkbook> </xml> <![endif]--> </head> <body><table class="table table-condensed table-striped table-hover table-bordered pull-left" id="myTable"><thead><tr><th>Rakesh</th><th>kumar</th></tr></thead><tbody><tr><th>Rakesh</th><th>Rakesh</th></tr><tr><th>Rakesh</th><th>Rakesh</th></tr><tr><th>Rakesh</th><th>Rakesh</th></tr><tr><th>Rakesh</th><th>Rakesh</th></tr></tbody></table></body></html>'; header('Content-type: application/excel'); header('Content-type: image/jpeg,image/gif,image/png'); header("Content-Disposition: attachment; filename=download.xls"); header("Pragma: "); header("Cache-Control: "); echo $content; ?>
如果你正确地做了,你可以帮助我与你的codeigniter代码。