troubleshooting Question

Problem with character encoding in AJAX

Avatar of elvin226
elvin226 asked on
8 Comments1 Solution930 ViewsLast Modified:
With AJAX, I'm having problem when submitting text that includes ascii characters (that are not readily available on the keyboard, e.g., ©, ñ, ®, ™). I found that these characters are sent/submitted in UTF-8, which is the default charset when using the send() function of Microsoft.XMLHTTP ActiveXObject, and appear differently when inserting into the database. The ñ comes as ñ, the © comes as ©, and so on. There is always this  or à character that is stored together with original character. If I have a char field in the database with a length of 1, it is apparent that this kind of encoding is a problem.

Here is a sample code that I use:


function submitForm()
    var sParams;

    oXMLHTTP = new ActiveXObject('Microsoft.XMLHTTP');

    with (oXMLHTTP)
        onreadystatechange = showSubmitResult;
        open('POST', 'saveData.asp?sid='+Math.random, true);
        setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        sParams = 'txtText=' + document.forms[0].txtText.value

A documentation I found on MSDN (, you might find it funny that IE7.0 detects this Microsoft website as a phising website) says that on the setRequestHeader method, I should include a charset attribute to override the default utf-8 encoding so I tried this:

        setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=iso8859-1');

Or this:

        setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        setRequestHeader('charset, 'iso8859-1');

Both didn't work.

I could just include the data to be submitted in the sUrl parameter of the open() method and retain the original encoding (iso8859-1) but there's another problem: the maximum URL length is 2083 on IE (

I just want to know how I can pass the data thru the send() method while retaining the iso8859-1 encoding.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 8 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 8 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004