Download file through an ajax call php

后端 未结 5 1329
别跟我提以往
别跟我提以往 2020-11-22 14:51

I have a button and onclick it will call an ajax function.

Here is my ajax function

function csv(){

    ajaxRequest = ajax();//ajax()          


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 15:17

    A very simple solution using jQuery:

    on the client side:

    $('.act_download_statement').click(function(e){
        e.preventDefault();
        form = $('#my_form');
        form.submit();
    });
    

    and on the server side, make sure you send back the correct Content-Type header, so the browser will know its an attachment and the download will begin.

提交回复
热议问题