Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a max data length for an ajax jQuery request

Tags:

jquery

ajax

max

I have the following jQuery click() function that needs to send the form data via ajax to the database.

$("#maandbutton").live('click', function(event) {
    $.get("ajax.php",{"action":"addm","maandtekst":$('#maandtekstinput').val(),"maand":$('#maandselect').val(),"bovenonder":$('#bovenonder').val()},function(msg){
       $("#maandtable").append($('<tr><td class="left">' + $('#maandtekstinput').val() + '</td><td class="right">' + $('#bovenonder').val() + '</td><td class="right">' + $('#maandselect').val() + '</td><td class="icon"></td></tr>'));
       $('table.zebra tr').removeClass('odd');
       $('table.zebra tr:odd').addClass('odd');
       $('#maandtekstinput').val('');
       $('#maandselect').val('');
       $('#bovenonder').val('');
       $("#maandbutton").button({ disabled: true });
   })
});

The problem is that if the textarea #maandtekstinput has to much text in it, only the append is working, but the data doesn't reach my sql database.

My ajax.php script has a simple switch statement.

$maandtekst = htmlspecialchars($_GET['maandtekst']);

switch($_GET['action'])
{
    case 'addm':
        $query = "INSERT INTO `site_maandteksten` (`id`, `maand`, `bovenonder`, `tekst`) VALUES (NULL, '".$maand."', '".$bovenonder."', '".htmlspecialchars_decode($maandtekst)."')";
        $result = mysql_query($query) or die(mysql_error());
        break;
}

I'm wondering why my script doesn't deliver my textarea text to the database. In my database it is a long text field with 5000 character space

like image 373
user1755868 Avatar asked Oct 18 '12 10:10

user1755868


1 Answers

Don't use a GET query for big data : use a POST one.

   $.post("ajax.php",{"action":"addm","maandtekst":$('#maandtekstinput').val(),"maand":$('#maandselect').val(),"bovenonder":$('#bovenonder').val()},function(msg){

(and in PHP use $_POST or $_REQUEST)

The problem with GET queries is that the parameters are embedded in the URL, which is limited in size (this limit is browser and server dependent).

like image 64
Denys Séguret Avatar answered Oct 13 '22 01:10

Denys Séguret