Download a file and redirect it to another page via ajax

后端 未结 12 2280
盖世英雄少女心
盖世英雄少女心 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:14

    By using https://github.com/johnculviner/jquery.fileDownload js:

    $.ajax({
        type: "POST",
        url: "/site/ajaxexcel.php", 
        data: {'value':'send'},
        cache: false,
        success: function(html)
            {
                $.fileDownload("ajaxheader.php",
                {
                    successCallback: function (url) {
                        location.href = '';    
                    },
                    failCallback: function (responseHtml, url) {
                        alert('error');
                    }
                });       
            }
    });
    

    And at php side add below line in headers:

    header("Set-Cookie: fileDownload=true; path=/");
    

提交回复
热议问题