laravel 下载文件时如何放置加载?

jfewjypa  于 2023-01-03  发布在  其他
关注(0)|答案(1)|浏览(111)

我有一个冲突,当我使用下面的代码,我不明白如何显示从SweetAlert2加载的警报,因为如果我把它放在windows.location之后,它会出现分钟秒,页面会不断重新加载,直到文件下载。

jQuery(document).on('click','#downloadExcel',function(e){
    e.preventDefault();

    var beginDate = $('#start').val();
    var endDate = $('#end').val();
    var projectData = $('select[name="project"]').val();

    if (beginDate > endDate) {
        Swal.fire(
            'error',
            'The start date cannot be greater than the end date.',
            'error'
        );
    }

    $('#begin_').html(beginDate);
    $('#end_').html(endDate);

    $('#exportsLeadsModal').on('click', 'a',function(e){
        var action_data = $(this).attr('data-id');

        var status = null;
        switch (action_data) {
            case 'all':
                status = 'leads';
                break;
            case '3':
                status = 3;
                break;
            case '4':
                status = 4;
                break;
            case '5':
                status = 5;
                break;
        }

        var token = '{{csrf_token()}}';
        var query = {
            location: '/import_export/old_leads_total',
            project: projectData,
            start: beginDate,
            end: endDate,
            status: status
        };

        var url = "import_export/old_leads_total?"+ $.param(query);
        //Here I put the swal and it appears microseconds and it closes by itself.
             Swal.fire({
                title: 'Please Wait !',
                html: 'data uploading',// add html attribute if you want or remove
                allowOutsideClick: false,
                onBeforeOpen: () => {
                    Swal.showLoading()
                },
            });

        window.location = url;

    });
});
icnyk63a

icnyk63a1#

尝试使用SweetAlert2。

// Show the loading indicator
Swal.fire({
  title: "Please wait...",
  html: "File is being downloaded",
  onBeforeOpen: () => {
    Swal.showLoading();
  },
});

// Start the download
window.location = '/path/to/yourbigfile.pdf';

// Close the loading indicator when finished
window.addEventListener("beforeunload", () => {
  Swal.close();
});

相关问题