Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Ajax - post huge string value

i need to POST a huge string large about 3mb, is it possible to send it to php using not url params?

If i send it in url params the request reachs the size limit in url.

How can work around this? any clue?

thanks a lot.

Actually i'm doing it like this:

$.ajax({
 type:'POST',
.......
data:{string:3MB_string}
});

i'm using PHP and jQuery , and i wouldl ike to send the 3mb base64 string to php on a simple url, like site.com/script.php

The string is a File Reader API base64 image

this is an example of string but this won't reach the size limit it is not a 3mb is less cause troubling in pasting that to show you a 3mb, http://jsfiddle.net/QSyMc/

like image 608
bombastic Avatar asked Jul 23 '13 12:07

bombastic


2 Answers

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
like image 143
Darin Dimitrov Avatar answered Sep 20 '22 21:09

Darin Dimitrov


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.

like image 28
krampstudio Avatar answered Sep 23 '22 21:09

krampstudio