I'm having problems with Firefox 3 beta 5 when sending UTF-8
characters via an XMLHTTPRequest.
I have read the following page: http://developer.mozilla.org/en/docs/XMLHttpRequest
which states:
Note: Versions of Firefox prior to version 3 always send the request
using UTF-8 encoding; Firefox 3 properly sends the document using the
encoding specified by data.xmlEncoding, or UTF-8 if no encoding is
specified.
In my test example, I attempt to explicitly set the content-type
header to "text/xml;charset=utf-8", as well as verify that the
xmlEncoding is null.
However, when I view the request headers in FF3 I see:
Content-Type text/xml; charset=ISO-8859-1
and the content on the server side is garbled
In FF2 I see:
Content-Type text/xml;charset=UTF-8
and t content is correctly encoded as UTF-8 on the server side
Here's an example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script language="javascript">
var dom = document.implementation.createDocument( "", "", null );
var element = dom.createElement( "content" );
element.appendChild( dom.createTextNode( "üßäöüß" ) );
dom.appendChild( element );
var request = new XMLHttpRequest();
var url ="someURL";
request.open( "POST", url, true );
request.setRequestHeader( "Content-Type", "text/xml;charset=utf-8" );
/* Firefox 3 should take it's cue from data.xmlEncoding, according to
http://developer.mozilla.org/en/docs/XMLHttpRequest */
alert( "xmlEncoding? " + dom.xmlEncoding );
request.send( dom );
</script>
</head>
<body>
</body>
</html>
Does anyone have any idea on how to control this? Or how to set the
xmlEncoding property if necessary? Or what I'm doing wrong ;) ?
Thanks,
Peter
Well does your server-side code read out the charset parameter (e.g.
ISO-8859-1) and use it to parse the contents? That is what you should do
I think.
However I think choosing ISO-8859-1 as the encoding is a bad choice, I
will ask in the XML newsgroup why that has been done and whether it can
be changed.
> Does anyone have any idea on how to control this? Or how to set the
> xmlEncoding property if necessary? Or what I'm doing wrong ;) ?
I don't think you can set xmlEncoding or characterSet, they are read only.
--
Martin Honnen
http://JavaScript.FAQTs.com/
>> Does anyone have any idea on how to control this? Or how to set the
>> xmlEncoding property if necessary? Or what I'm doing wrong ;) ?
>
> I don't think you can set xmlEncoding or characterSet, they are read only.
What should be possible, instead of passing the DOM document to the send
method is passing the serialization of the document as a string to the
send method, that way the string is UTF-8 encoded I think:
httpRequest.send(new XMLSerializer().serializeToString(domDocument));