ajax 响应数据的最大大小是多少?
我从 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。实际上文本可能包含1MB的数据......
问题出在哪里?
I send request from asp.net page and then wait for response, calling GetCommand via SetInterval method:
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;
}
});
}
In AjaxFinishedGet(result, status) I try to extract my data:
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");
}
}
}
However, if Text size is more than 102330 bytes - instead of AjaxFinishedGet, AjaxFailedGet is called :(
I have not found any info neither about some limitation of ajax response data size nor about javascript variable size, at least such variable can hold 1MB without problems. Actually Text may contain 1MB of data...
Where is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,多个请求可能会导致错误,也许一个好的解决方案是验证当前没有活动的请求。
Well, multiple requests can cause error, perhaps a good solution is to verify that there is no active current request.
詹姆斯·布莱克,我没有任何有关错误的信息:
Web服务器是Vista x32 zazk上的IIS7
,
谢谢,进行这样的检查是一个好点,为了可靠性我将使用这个标志。但是,在给定的情况下,我不认为这可能是问题的原因:当数据大小为 102330 时,响应输出始终有效,并且从 102331 开始不起作用(我正在使用 new String('x' ,102330),所以它不可能是任何特殊字符问题或类似的问题)。
James Black, i have no any info about the error:
WebServer is IIS7 on Vista x32
zazk,
thanks, putting such check is a good point and i will use this flag for reliability. However, in the given case, i don't think it could be the reason of the problem: response output does work always, when data size is 102330 and doesn't work starting from 102331 (i am using new String('x', 102330), so it cannot be any special character problem or something like that).
.NET 的 web.config 文件中默认设置为 4mb
因为
maxRequestLength
是 INT,所以理论最大值是 INT 最大值,即 2,147,483,647There is a default setting in the web.config file for .NET is 4mb
Because
maxRequestLength
is an INT, the theoretical maximum is the INT max value which is 2,147,483,647我刚刚遇到了一个严重的错误,我追踪到 AJAX 调用返回的字符串的长度。大约是 63639 (iirc),接近 ushort 的限制(再次,iirc!)(我猜 iis 附加了自己的内容来弥补字符限制的其余部分)。
我设法从字符串中的 html 中去掉所有样式,并在客户端收到它时通过 JQuery 附加它! :)
I just had a nasty error which i tracked down to the length of a string being returned from an AJAX call. It was about 63639 (iirc) which is close to the limit of a ushort (again, iirc!) (I guess iis appends its own stuff to make up the rest of the character limit).
I managed to strip the all the styling out of the html in the string and append it through JQuery when it was received by the client! :)