0

I would like to know how to export an excel file using ajax, I have tried in the following way, but it does not work:

$("#ajax_loader").css("display", "");
    var formato = "PDF";

    //window.location.href = url;
    //$("#ajax_loader").hide();
    var fd = new FormData();
    fd.append("format", formato);
    fd.append("nombreObra", $('#nombre_obra').val());
    $.ajax({
        type: "POST",
        url: '<%= Url.Action("Export", "Obras")%>',
        data: fd,
        DataType: 'json',
        contentType: false,
        processData: false,
        success: function (data) {
            $("#ajax_loader").hide();
        }
    });
 });

If anyone has any ideas, I would greatly appreciate it. Greetings.

  • You'd need a `javascript` way to convert your data to csv https://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side OR set the headers on the server `'Content-disposition', 'attachment; filename=some-filename.csv'` & `'Content-Type': 'text/csv'` – Lex Jul 03 '18 at 04:53
  • In title you mentioned *Export pdf fille* and in description *export an excel file*. So what you want to achieve? And also post your controller code. – mmushtaq Jul 03 '18 at 05:07

0 Answers0