Why do browsers encode special characters differently with ajax requests?
- by Andrei Oniga
I have a web application that reads the values of a few input fields (alphanumeric) and constructs a very simple xml that is passes to the server, using jQuery's $.ajax() method.
The template for that xml is:
<request>
    <session>[some-string]</session>
    <space>[some-string]</space>
    <plot>[some-string]</plot>
    ...
</request>
Sending such requests to the server when the inputs contain Finnish diacritical characters (such as ä or ö) raises a problem in terms of character encoding with different browsers. For instance, if I add the word Käyttötarkoitus" in one of the inputs, here's how Chrome and Firefox send EXACTLY the same request to the server:
Chrome:
<request>
    <session>{string-hidden}</session>
    <space>2080874</space>
    <plot>Käyttötarkoitus</plot>
    ...
</request>
FF 12.0:
<request>
    <session>{string-hidden}</session>
    <space>2080874</space>
    <plot>Käyttötarkoitus</plot>
    ...
</request>
And here is the code fragment that I use to send the requests:
$.ajax({ 
    type: "POST", 
    url: url,
    dataType: 'xml;charset=UTF-8',
    data: xml, 
    success: function(xml) { 
        //
    },
    error: function(jqXHR, textStatus, errorThrown) {
        //
    }
});
Why do I get different encodings and how do I get rid of this difference? I need to fix this problem because it's causing other on the server-side.