Ajax File Download using Jquery, PHP

后端 未结 2 1842
我在风中等你
我在风中等你 2020-11-27 03:28

I want to use the ajax functionality to download whereby the user will click the download link which will (using ajax and $_GET) access a PHP file which will process the sen

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 03:46

    I know I'm late! But I think I have a solution that's a little cleaner without the use of a hidden iframe and you won't even need an ajax request to do it! Using PHP Headers as noted in the accepted answer in a download.php file

    And on the JS end, simply

    function download(filename){
        window.location="http://whateveryoursiteis.com/download.php?file="+filename;
    }
    

    Works like a charm :O

提交回复
热议问题