user1755868
user1755868

Reputation: 175

Is there a max data length for an ajax jQuery request

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

Upvotes: 6

Views: 5660

Answers (1)

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382092

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).

Upvotes: 3

Related Questions