Download a file and redirect it to another page via ajax

后端 未结 12 2244
盖世英雄少女心
盖世英雄少女心 2021-02-02 09:44

I have a simple contact form for download excel file . Main issue happen , When ajax load .I want to download excel file then redirect user to a next page.. Below is my code wit

12条回答
  •  情歌与酒
    2021-02-02 10:08

    Method 1 : with jQuery AJAX

    Replace your ajax with the following code..

       
    

    window.open will open the ajaxexcel.php file in separate window and location.href will redirect to given welcome.php file.This is the best method for this.

    Method 2 : with jQuery filedownload plugin

    Just include jqueryfiledownload script and do something like this:

    Download
    
    

    Now when you click on anchor your file is downloaded and you can write your success/failure code in done()/fail() functions respectively.

提交回复
热议问题