2009-11-10 104 views
2

我从asp.net页面发送请求,然后等待响应,通过setInterval的方法调用GetCommand:ajax响应数据的最大大小是多少?

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(结果状态),我尝试提取我的数据:

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的数据...

问题在哪里?

+1

抛出什么错误?你使用哪个网络服务器? – 2009-11-10 17:51:50

回答

1

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

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

} 

function AjaxFinishedGet(xml, status) { 
    loading = false; 
    ... 
    ... 
} 
1

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

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

WebServer的是IIS7在Vista的X32

zazk, 感谢,把这种检查是一个很好的点,我会使用该标志的可靠性。然而,在特定的情况下,我不认为这可能是问题的原因:响应输出始终工作,当数据大小为102330,并从102331开始无效(我正在使用新的String('x' ,102330),所以它不能是任何特殊的人物问题或类似的东西)。

0

有在.NET web.config文件默认设置为4MB

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

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

0

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

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

相关问题