I have a javascript function that continually adds data to an array based on the user’s actions. The array is intended to be sent out via ajax to a website on a different URL, so i’ll be using GET.
Since GET requests are limited in size, my plan is to have javascript monitor the array and send the data out when it approaches the max size of a GET request (I’ve read about 8kb).
I know that POST would be preferable but I need to send the array to another domain.
How can I find out when the array contents are ~7kb so I can trigger the ajax request?
The array has to be serialized to a string for transmission, no? (Somebody has to do it, be it jQuery or whatnot).
I might be tempted to simply perform an incremental serialization and monitor the resulting string length — that is, if there was no way to avoid this issue entirely 🙂 There is likely no performance issue with simply performing a full serialization and checking the resulting string length; just use an appropriate trigger/poll setup.
Happy coding.