Is it any limit for POST data size in Ajax?

前端 未结 6 1557
小蘑菇
小蘑菇 2020-11-28 09:41

I\'m trying to send an array of data from my page to the MVC Action using jQuery Ajax. Here is my jQuery code:

$(\'#btnSave\').click(
  function () {
    res         


        
相关标签:
6条回答
  • 2020-11-28 10:22

    IF there is a client-side limit then it would be browser specific but the HTTP spec does not define a limitation of POST data size.

    Keep in mind that a POST is merely bytes across the network so the more fields you are posting then the longer it can take to upload that data.

    A 1MB POST is going to make the user feel like the form is broken and unresponsive if using a traditional form submit.

    If there are a lot of fields to serialize() then AJAX could hang up the browser while it collects all of the data. I think browsers do have a memory limit for JavaScript overall so if you hit that limit then the AJAX process will fail.

    // wanna have some fun?
    var html = '<div></div>';
    
    for(var i = 0; i < 1000000; i++){
        html += html;
    }
    

    Your best bet is to increase the maximum allowable POST size on the server-side to avoid issues.

    Most commonly issues arise when people make an upload script which simply seems to hang while the user is confused why their 3MB pictures are going slow on a 125KB/s upload link.

    0 讨论(0)
  • 2020-11-28 10:28

    Is it any POST Limit in Ajax?

    No, the HTTP specification doesn't impose a specific size limit for posts. However it depends on the Web Server which you are using or the programming technology used to process the form submission.

    In ASP.NET MVC you can try this:

    <system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="1000000" />
        </requestFiltering>
    </security>
    
    0 讨论(0)
  • 2020-11-28 10:34

    The limit is set through a server 'max_post_size' or similar naming. Typical default server settings are 2-8 MB in one post.

    On the client side, only GET has a maximum limit, generally considered 1500 bytes (minus 30-150 from request headers) and the reason is the MTU in the more lowlevel network hardware

    0 讨论(0)
  • 2020-11-28 10:39

    The HTTP spec doesn't defining a limitation of POST data size.

    But using ASP.NET MVC, there could be a POST data limitation, try to increase it in your Web.Config file:

    <system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="1000000" />
        </requestFiltering>
    </security>
    

    From MSDN:

    Specifies the maximum length of content in a request, in bytes. The default value is 30000000.

    0 讨论(0)
  • 2020-11-28 10:44

    JSON has a maximum length! I need to increase this value. In web.config add the following:

    <appSettings>
      <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
    </appSettings>
    
    0 讨论(0)
  • 2020-11-28 10:47

    This solved my problem:

    <system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="2147483647" />
            </webServices>
        </scripting>
    </system.web.extensions>
    
    0 讨论(0)
提交回复
热议问题