微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AJAX xhr 进度功能和经典的 asp response.clear/response.flush 不起作用

如何解决AJAX xhr 进度功能和经典的 asp response.clear/response.flush 不起作用

我正在尝试显示来自 Ajax 调用的长时间运行进程的周期性状态。问题是只有第一个 response.clear 有效。当我在第一次清除后刷新时,我得到了前面的所有输出,而不仅仅是清除后的输出

在生产代码中,我求助于输出“||”每次写入后分解响应,然后在“||”上拆分并获取该数组中的最后一个元素。但是,我不想这样做。

Ajax 调用

$(document).on(`dragover drop`,`#AmazonListingReport`,function(e) {
    $(`#AmazonListingReportrMsg`).text(``);
    e.stopPropagation();
    e.preventDefault();
    files = [];
    if (e.type === `drop`) {
        form_data = new FormData();
        file = e.originalEvent.dataTransfer.files[0];
        form_data.append(`txtFile`,file);
        form_data.append(`action`,`processAmazonAllListingsFile`);
        let statusText = `Uploading`;
        updateStatus($(`#AmazonListingReportrMsg`),statusText);
        $.ajax({
            xhr: function() {
                let myXhr = new XMLHttpRequest();
                myXhr.addEventListener(`progress`,function() {
                    if (statusText !== myXhr.responseText) {
                        statusText = myXhr.responseText;
                        console.log(`update status`,statusText);
                        clearInterval(updateStatusTimer);
                        updateStatus($(`#AmazonListingReportrMsg`),statusText);
                    }
                },false);
                if (myXhr.upload) {
                    myXhr.upload.addEventListener(`progress`,function(e) {
                        if (e.lengthComputable) {
                            $(`#processprogress`).attr({
                                value: e.loaded,max: e.total,});
                        }
                    },false);
                }
                return myXhr;
            },url: `KP_ManageAmazonSeasonalOrders_AJAX.asp`,data: form_data,cache: false,contentType: false,processData: false,enctype: `multipart/form-data`,type: `POST`,}).done(function(data) {
            console.log(`data`,data);
        }).fail(function(xhr,textStatus,errorThrown) {
            console.log(xhr,errorThrown);
        }).always(function() {
            clearInterval(updateStatusTimer);
        });
    }
});

过程:

sub processAmazonAllListingsFile()
    response.write "You should never see this"
    response.clear '<---this works. I never see the above string
    response.write "Starting"
    response.write vbCrLf
    response.flush '<--This works. Returns "Starting"
    response.clear
    '<LONG RUNNING PROCESS HERE>
    response.write "converting file" 
    response.write vbCrLf
    response.flush '<--returns "Startingconvertingfile"
    response.clear
    '<LONG RUNNING PROCESS HERE>

    response.write "Excel File Saved. Updating Products" 
    response.write vbCrLf
    response.flush '<--Here,I get "Startingconverting fileExcel File Saved. Updating Products"
    response.clear
    '<LONG RUNNING PROCESS HERE>
    response.write "done copying to sql server"  
    response.write vbCrLf
    response.flush '<--Here,I get "Startingconverting fileExcel File Saved. Updating Productsdone copying to sql server"
    response.clear
    response.end
end sub

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。