Jquery Ajax - post huge string value

You will need to use a POST request:

$.ajax({
    url: '/script.php',
    type: 'POST',
    data: { value: 'some huge string here' },
    success: function(result) {
        alert('the request was successfully sent to the server');
    }
});

and in your server side script retrieve the value:

$_POST["value"]

Also you might need to increase the allowed request size. For example in your .htaccess file or in your php.ini you could set the post_max_size value:

#set max post size
php_value post_max_size 20M

Try with processData to false and a string representation of your JSON

var data = { "some" : "data" };
$.ajax({
    type: "POST",
    url: "/script",
    processData: false,
    contentType: 'application/json',
    data: JSON.stringify(data),
    success: function(r) {
       console.log(r);
    }
});

From the jQuery.ajax documentation :

processData (default: true)

Type: Boolean

By default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send a DOMDocument, or other non-processed data, set this option to false.


I came across a similar problem. It wasn't the length of the query string but rather the number of variables I was passing to the server. The php.ini places a limit in the max_input_vars field to 1200 variables. In my case, I was exceeding that amount rather than the post_max_size amount. Had to go back and make the query more efficient and under the limit. I guess I could have raised the php.ini setting but I wound up with better code by disabling non-essential query parameters.