当传出的Content-Length超过3508字节时,XMLHttpRequest失败。为什么?

时间:2010-11-08 13:43:13

标签: asp.net asp.net-mvc firefox jquery

更新:我已经继续前进,而不是寻找答案

更新:请参阅下面的上一次更新。

我正在使用JQuery的jQuery.ajax()函数执行POST请求,并且当传出的Content-Length超过3508字节时出现错误并且不返回任何响应。只要Content-Length保持在3509字节以下,一切都会正常工作。

以下是我注意到的其他一些事情:

  • 如果我将方法从POST更改为GET一切正常,但由于URL具有(浏览器特定的)最大长度,我认为我不能这样做(例如最大长度为2,083 Internet Explorer的字符)。

  • 当我执行正常的非XMLHttpRequest表单POST时,一切正常(即使Content-Length远远超过3508字节)。

  • Firefox(3.6.12)仍将调用成功处理程序,数据为“未定义”,而Internet Explorer(8)将调用错误处理程序,textStatus为“error”,errorThrown为“undefined”。

请注意,在“服务器端”,我正在运行ASP.NET Development Server并使用ASP.NET MVC 1.0。

这基本上就是我正在做的事情:

$.ajax({
    type: "POST",
    url: "", // A resource on localhost
    // The following string results in a Content-Length of 3509 bytes
    data: "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
    success: function(response) {
        alert(response);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert(textStatus + " " + errorThrown);
    },
    dataType: "json"
});

有什么想法吗?

更新

以下是失败请求的请求标头(没有响应):

POST /WPA/BerekenEindcijfer HTTP/1.1
Host: localhost:4387
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729)
Accept: application/json, text/javascript, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:4387/WPA
Content-Length: 3509

更新:我将应用程序发布到IIS(5.1)并且问题没有在那里发生,奇怪的是现在问题现在也不再使用ASP.NET开发服务器了。由于某种原因,请求中出现了两个新标题(虽然我不确定它们是否有任何影响):

Pragma: no-cache
Cache-Control: no-cache

我仍然感到困惑的是什么/正在发生。

1 个答案:

答案 0 :(得分:2)

您是否尝试在web.config中更改此内容:

 <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="5000"/>
      </webServices>
    </scripting>

Configuring JSON Serialization