下载没有重定向php的链接

时间:2017-07-24 10:05:49

标签: php jquery ajax

我正在尝试创建按钮来下载带有ajax调用的文件,但是ajax调用获取响应中的文件内容但不创建下载,(下载文件是正确的,如果你创建了下载输入网址

<div class="col-md-3" id="export-btn">
    <button class=" btn btn-success">Exportar</button>
</div>

ajax电话

$('#export-btn').on('click',function(){
    $.ajax({
        url: "download.php",
        method:'get'
    }).done(function(response){
        console.log(response);
    });
});

这是下载文件,工作正常

<?php
    header('Pragma: public');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Cache-Control: private', false);
    header('Content-Type: application/octet-stream');
    header('Content-Transfer-Encoding: binary');
    header('Content-Disposition: attachment; filename="cataleg_peticions.csv"');

    $url = "cataleg_peticions.csv";
    readfile($url);
    exit();
?>

0 个答案:

没有答案