E
ebs2002
I am working with an AJAX Rich-Text Editor that needs to send its text
to a server for different purposes.
Frequently, the RTE will have characters outside of the ISO-8859-1
character set (the one that is failing testing is '-', or '–'
but many other unicode characters are also being processed
incorrectly).
My test scenario is as follows:
1) If I submit '-' through an HTML form as an input value in Firefox,
my servlet recognizes it as a single character, and submits it into my
database properly.
2) If I submit '-' through an XMLHttpRequest submit, my servlet thinks
the character is a string of four separate characters, and I can't
figure out why.
The javascript for (2) :
var xmlhttp = new XMLHttpRequest();
var params="text="+encodeURIComponent("-");
alert(params); // displays 'text=%E2%80%93
xmlhttp.onreadystatechange = requestcomplete;
xmlhttp.open('POST', url, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-
urlencoded; charset=utf-8");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "keep-alive");
The same behavior results if I set the charset to ISO-8859-1, or if I
omit it entirely.
I've analyzed the Request Headers for both forms, and they look
identical. Is there anything that Firefox is doing differently than
what my xmlhttprequest object is doing?
to a server for different purposes.
Frequently, the RTE will have characters outside of the ISO-8859-1
character set (the one that is failing testing is '-', or '–'
but many other unicode characters are also being processed
incorrectly).
My test scenario is as follows:
1) If I submit '-' through an HTML form as an input value in Firefox,
my servlet recognizes it as a single character, and submits it into my
database properly.
2) If I submit '-' through an XMLHttpRequest submit, my servlet thinks
the character is a string of four separate characters, and I can't
figure out why.
The javascript for (2) :
var xmlhttp = new XMLHttpRequest();
var params="text="+encodeURIComponent("-");
alert(params); // displays 'text=%E2%80%93
xmlhttp.onreadystatechange = requestcomplete;
xmlhttp.open('POST', url, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-
urlencoded; charset=utf-8");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "keep-alive");
The same behavior results if I set the charset to ISO-8859-1, or if I
omit it entirely.
I've analyzed the Request Headers for both forms, and they look
identical. Is there anything that Firefox is doing differently than
what my xmlhttprequest object is doing?