使用第二个 jquery 请求上传文件

File upload with second jquery request

我使用 jquery ajax 和进度条 (xhr) 上传文件。

$.ajax({
    url: "../Services/upload.ashx",
    type: "POST",
    data: formData,
    cache: false,
    contentType: false,
    processData: false,
    timeout: 60000
    xhr: function () {
        var myXhr = $.ajaxSettings.xhr();
        if (myXhr.upload) {
            myXhr.upload.addEventListener('progress', that.progressHandling, false);
        }
        return myXhr;
    }

Upload.prototype.progressHandling = function (event) {
    var percent = 0;
    var position = event.loaded || event.position;
    var total = event.total;
    if (event.lengthComputable) {
        percent = Math.ceil(position / total * 100);
    }
};

进度条完美运行。文件已上传到服务器,但上传后需要在服务器端进行一些处理。我尝试通过发出另一个 jquery ajax 请求来检查此服务器端处理的状态。

问题出在第二次调用的响应上。我无法收到此回复,因为第一个(文件上传)仍在等待处理。

恕我直言,这两个请求是异步的,所以为什么如果我长时间上传文件 运行 服务器端处理会阻止我接收来自其他 ajax 调用的任何其他响应?

问题不在于 jquery ajax。问题是服务器 siade - 具有通用处理程序。它使用会话,因此它将阻止任何其他请求。

请查看此线程以获取更多信息:

https://forums.asp.net/t/1798041.aspx?A+request+to+a+long+running+handler+blocks+all+requests+to+other+pages

When requests come in, Session holds an exclusive lock so that other requests from the same session will not run in parallel and must run one after the other.