Receiving a .xls file using Ajax jquery POST

前端 未结 2 934
囚心锁ツ
囚心锁ツ 2021-02-06 19:57

I\'m attempting to return an Excel file through a Ajax POST to the server, the server generates the .xls file, however it doesn\'t pass through to the front end, i

2条回答
  •  鱼传尺愫
    2021-02-06 20:37

    Try this http://jsfiddle.net/abLeR/

    It downloads a tar file using hidden iFrame and ajax. Same can be used for the xls file.

    HTML

    Download
    
    

    Javascript

    $(".download").click(function (e) {
    
        e.preventDefault();
        var link = $(this);
        $('.loading').show();
    
        $.ajax({
            type: 'HEAD',
            url: link.attr('href'),
            complete: function () {
    
                $('.loading').hide();
                var ifr = $('