This question was asked by someone else, but no decent answer was given. Let me help by explaining my particular situation so there is no mixup that I am using AJAX at the moment (I am NOT for the sake of this question, but I may switch someday)…
I am submitting a form via a regular HTML to PHP submit using POST, which, in my case, has a lot of text, sometimes enough to exceed the POST limit. Is there a way via JavaScript to calculate if the POST will be too big before it’s submitted? If there’s no easy way to automatically determine the server’s POST limit, I can handle that manually, but I need to calculate the bytes to be sent and stop it (and send back a warning message) that it will not calculate.
Thanks in advance!
It should be easy to determine the size of the
POSTrequest so long as it’s just text input. If you also have file inputs it’ll be a bit harder but doable with HTML5 stuff.Just add up all the fields and their values.
Typically
POSTform-data looks like:"key=value&key2=value"So add 1 byte for each field (for the
=), and n-1 bytes in total (for the&).Then get a good number for the header, 100 bytes or so? Maybe 200.