下载文件并通过ajax将其重定向到另一个页面

Kum*_*esh 26 ajax jquery wiki codeigniter

我有一个简单的下载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" ?>';                 
    }
});
Run Code Online (Sandbox Code Playgroud)

我的ajaxexcel.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;
?>
Run Code Online (Sandbox Code Playgroud)

我想只下载excel文件,然后将用户重定向到特定位置.

如果您已正确完成,也可以帮助我使用您的codeigniter代码.

shy*_*.me 5

尝试下面的方法,希望它会工作

  1. ajaxexcel.php通过新窗口打开window.open
  2. 它将开始下载,然后关闭它.
  3. 一旦关闭,重定向页面.


Rav*_*lal 2

你可以用jquery.fileDownload.js这个。你可以在这里找到一个例子。。。http://www.codeasearch.com/working-with-jquery-filedownload-js-plugin.html