I have a $.post() that is trying to send a serialized form as the data, but also some additional variables from the page. One of them is the HTML code of the #designer-window div. This HTML can be thousands of characters long, in my example its 3411 characters.
The post request looks like this:
var html = $('#designer-window').html();
var cardid = $('input[name="cardid"]').val();
var id_card = $('input[name="id_card"]').val();
$.post('sv/ajaxadmin/', $('form[name="savecard"]').serialize()+"&html="+html+"&image="+renderedImage+"&cardid="+cardid+"&id_card="+id_card, function(data){
location.html(original);
$('form[name="savecard"] button').attr("disabled", false);
$('form[name="savecard"]').prepend(data);
console.log(data);
}, "text");
Now, if I use console.log(html); to print the data before it is send. I get the complete HTML string. However in my /sv/ajaxadmin/, if i echo $_POST['html']; then the string is cut off halfway through. The end of the string is missing.
So what I'm guessing is that there is some kind of limit with the amount of characters or bytes you can send using the function above, so the whole string isnt send. Only parts of it.
So a few things:
Maybe there is another way to set the post data to be send in the jQuery.post() function? Obviously I can use {data: var, data2: var2...}, the problem with this is combining it with $('form').serialize(). Is it possible?
Anyone know if there actually is a limit? I have not found any information regarding a byte/character-limit in jquery post requests. But the only way I can see it, is that there is a limit that is the cause of this issue. Do you have any other ideas?
EDIT:
After additional testing I noticed that it seems to have to do with the & character. So in the HTML, if a string contained & that meant that the $.post() data-query-string would get cut off. I tried escaping/replacing & with &
but it still mess up the query. So... How the question is then, how do I escape &'s to be able to send them in my query.
SOLVED: I wrapped my html variable with encodeURIComponent(); to escape it. Worked!