douxun2018 2019-03-27 17:31
浏览 59

如何通过ajax将数百万行从DB导出到CSV?

I have million rows in my DB. I need to export all them into csv file. The problem is that i have timeout limit error.

So. I decided to do it via ajax.

I created ajax that generates me few tmp csv files

function chunkedExport()
{
    $.ajax({
        type: "POST",
        url: "transactions/",
        dataType: "JSON",
        data: $("#transactions").serialize(),
        async: false,
        success: function(response)
        {
            if (response.status === "continue")
            {
                $("#start_from").val(response.start_from);
                $("#client_file_name").val(response.client_file_name);
                $("#file_name").val(response.tmp_file_name);
                $("#step").val(response.step);
                chunkedExport();
            } else {
                console.log('DOWNLOAD');
                $("#start_from").val(0);
                $("#client_file_name").val('');
                $("#file_name").val('');
                $("#step").val(1);
                $("#export_type").val("");
                $('#csv_format').val("");

                document.location.href = '/transactions_export_csv/'+response.client_file_name+'/'+response.tmp_file_name+'/'+response.total_iterations+'/'
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            console.log([xhr, ajaxOptions, thrownError]);
            $("#start_from").val(0);
            $("#client_file_name").val('');
            $("#file_name").val('');
            $("#step").val(1);
            $("#export_type").val("");
            $('#csv_format').val("");
        }
    });
}

the question is how to combine them all into one csv file and download it?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 nginx中的CORS策略应该如何配置
    • ¥30 信号与系统实验:采样定理分析
    • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
    • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
    • ¥15 php 同步电商平台多个店铺增量订单和订单状态
    • ¥15 关于logstash转发日志时发生的部分内容丢失问题
    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题