user1134179 user1134179 - 2 months ago 11
Javascript Question

Issue posting a large amount of data when using json in a query string

I'm posting four JSON objects to the server using a jQuery ajax request. Each object can be up to 30k characters. When all of the parameters are large the last parameter or even the last two parameters do not show up on the server. Everything works fine when the parameters are smaller though.

In chrome's network tab I see all of the parameters in their entirety. In fiddler I see the parameters in their entirety but the parameters that don't show up on the server will not have a name.

Fiddler

fiddler snippit

The structure of my request is as follows:

var formData = "json0=" + JSON.stringify(json0) + "json1=" + JSON.stringify(json1); //etc
$.ajax({
type: 'POST',
url: url,
data: formData,
success: function (result) {},
error: function() {}
});


I wouldn't think there would be a limit on a POST but it's acting like the data is being truncated for some reason. Server side I'm in Java using ParameterAware to retrieve the data but I think the issue is before it gets there since fiddler doesn't have the parameters' names.

Answer

Query strings are not made for large amounts of data, you should pass your data to your Ajax call in an object:

$.ajax({
    type: 'POST',
    url: url,
    dataType: "JSON",
    data: {
        json0: json0,
        json1: json1
        // etc
    },
    success: function (result) {},
    error: function() {}
});

Have a look at this article discussing the maximum length of query strings.

jQuery AJAX documentation: http://api.jquery.com/jQuery.ajax/