2

我从 asp.net 页面发送请求,然后等待响应,通过 SetInterval 方法调用 GetCommand:

    function GetCommand(id, sid) {
    getCommandResponse = $.ajax({
        type: "POST",
        async: true,
        url: "../WebServices/TSMConsole.asmx/GetCommand",
        data: "{'param' : '" + id + "', 'sid' : '" + sid + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result, status) {
            AjaxFinishedGet(result, status);
            getCommandResponse = null;
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            AjaxFailedGet(XMLHttpRequest, textStatus, errorThrown);
            getCommandResponse = null;
        }
    });
}

在 AjaxFinishedGet(result, status) 我尝试提取我的数据:

    function AjaxFinishedGet(xml, status) {
    endDate = new Date();
    if (xml.d.IsPending == 'false' || endDate - startDate > timeoutMSec) {
        if (getCommand != null) {
            window.clearInterval(getCommand);
            getCommand = null;
            WriteGetCommand(xml.d.Text);
            $("#showajax").fadeOut("fast");
        }
    }
}

但是,如果文本大小超过 102330 字节 - 而不是 AjaxFinishedGet,则调用 AjaxFailedGet :(

我没有找到任何关于 ajax 响应数据大小的限制或关于 javascript 变量大小的信息,至少这样的变量可以毫无问题地保持 1MB。实际上 Text 可能包含 1MB 的数据...

问题出在哪里?

4

4 回答 4

1

好吧,多个请求可能会导致错误,也许一个好的解决方案是验证没有活动的当前请求。

var loading = false;
function GetCommand(id, sid) {
    if (loading) {return false;}
    loading =  true;
        getCommandResponse = $.ajax({
         ....
         ....
        });

}

function AjaxFinishedGet(xml, status) {
    loading = false;
    ...
    ...
}
于 2009-11-10T19:23:59.547 回答
1

詹姆斯布莱克,我没有关于该错误的任何信息:

function AjaxFailedGet(XMLHttpRequest, textStatus, errorThrown) {
    $("#<%= tbResponse.ClientID %>").text(errorThrown);
    if (getCommand != null) {
        window.clearInterval(getCommand);
        $("#showajax").fadeOut("fast");
    }
}
  • errorThrown 为空。

WebServer 是 Vista x32 上的 IIS7

zazk,谢谢,进行这样的检查是一个很好的观点,我将使用这个标志来保证可靠性。但是,在给定的情况下,我不认为这可能是问题的原因:当数据大小为 102330 并且从 102331 开始时(我正在使用 new String('x' , 102330),所以它不可能是任何特殊字符问题或类似问题)。

于 2009-11-11T00:05:55.903 回答
0

.NET 的 web.config 文件中有一个默认设置是 4mb

<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>

因为maxRequestLength是 INT,所以理论上的最大值是 INT 最大值,即 2,147,483,647

于 2012-11-08T00:28:38.483 回答
0

我刚刚遇到了一个令人讨厌的错误,我追踪到了从 AJAX 调用返回的字符串的长度。它大约是 63639 (iirc),接近 ushort 的限制(再次,iirc!)(我猜 iis 附加了自己的东西来弥补字符限制的其余部分)。

我设法从字符串中的 html 中去除所有样式,并在客户端收到它时通过 JQuery 附加它!:)

于 2013-06-18T14:35:59.723 回答