Character Encoding not identical between XMLHttpRequest and a form submit

Discussion in 'Javascript' started by ebs2002@gmail.com, Sep 18, 2007.

  1. Guest

    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?
     
    , Sep 18, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    13
    Views:
    639
    Bryan Castillo
    Oct 28, 2004
  2. raavi
    Replies:
    2
    Views:
    913
    raavi
    Mar 2, 2006
  3. Guest
    Replies:
    2
    Views:
    1,603
    Guest
    Oct 25, 2004
  4. Megha Vishwanath
    Replies:
    3
    Views:
    718
    Megha Vishwanath
    Jul 20, 2004
  5. Replies:
    3
    Views:
    702
Loading...

Share This Page