I have some lengthy JSON text that I am sending back to the server via Ajax:
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", myVeryLongAJAXText.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {...}
http.send(myVeryLongAJAXText);
Do I need to change the last line to:
http.send(encodeURI(myVeryLongAJAXText));
or does the send method take care of that?
You need to encode them on the client, and decode them on the server. It will work undecoded, but it’s less error prone, and safer to encode/decode.
Send doesn’t offer that because the data being sent could be just a single integer, so calling UrlEncoding would introduce unneeded overhead.