Character Encoding not identical between XMLHttpRequest and a form submit

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top