HighDots Forums  

XHR und encoding

Javascript (German) Programmiersprache JavaScript. (de.comp.lang.javascript)


Discuss XHR und encoding in the Javascript (German) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris Seidel
 
Posts: n/a

Default XHR und encoding - 10-25-2009 , 06:04 AM






Hallo,

ich hole via XHR eine Textdatei vom Server:

xmlhttp.open("GET", url, false);
xmlhttp.send(null);
var text = xmlhttp.responseText;

Request
Host localhost:8081
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.9.0.14)
Gecko/2009082707 Firefox/3.0.14 (.NET CLR 3.5.30729)
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0..8
Accept-Language de-de,en;q=0.7,de;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7


Response
Server Apache-Coyote/1.1
Etag W/"98-1256399055209"
Last-Modified Sat, 24 Oct 2009 15:44:15 GMT
Content-Length 98
Date Sun, 25 Oct 2009 09:52:17 GMT


Die Datei ist ISO-8859-1 kodiert. Leider kommen im Javascript Umlaute
zerschossen an.

Setze ich xmlhttp.overrideMimeType("text/plain; charset=ISO-8859-1");
klappt es.

Fragen:

1. Müsste es nicht per Default ISO-8859-1 sein?
2. Wie löse ich das im IE, der kennt overrideMimeType nicht.

Danke

Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: XHR und encoding - 10-25-2009 , 07:08 AM






Chris Seidel wrote:

Quote:
Response
Server Apache-Coyote/1.1
Etag W/"98-1256399055209"
Last-Modified Sat, 24 Oct 2009 15:44:15 GMT
Content-Length 98
Date Sun, 25 Oct 2009 09:52:17 GMT


Die Datei ist ISO-8859-1 kodiert. Leider kommen im Javascript Umlaute
zerschossen an.
Dann sollte der Server den HTTP header
Content-Type: text/plain; charset=ISO-8859-1
senden. Woher sonst soll der Browser wissen, welche Kodierung die
Antwort hat?





--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/

Reply With Quote
  #3  
Old   
Chris Seidel
 
Posts: n/a

Default Re: XHR und encoding - 10-25-2009 , 07:41 AM



On Sun, 25 Oct 2009 12:08:21 +0100, Martin Honnen <mahotrash (AT) yahoo (DOT) de>
wrote:

Quote:
Dann sollte der Server den HTTP header
Content-Type: text/plain; charset=ISO-8859-1
senden. Woher sonst soll der Browser wissen, welche Kodierung die
Antwort hat?
Ist ISO-8859-1 nicht default, wenn nichts gesetzt ist?

Reply With Quote
  #4  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: XHR und encoding - 10-25-2009 , 07:49 AM



Chris Seidel wrote:

Quote:
Martin Honnen wrote:
Dann sollte der Server den HTTP header
Content-Type: text/plain; charset=ISO-8859-1
senden. Woher sonst soll der Browser wissen, welche Kodierung die
Antwort hat?

Ist ISO-8859-1 nicht default, wenn nichts gesetzt ist?
Ja, ist es nicht. Jedenfalls in der Praxis.

<http://www.w3.org/TR/html401/charset.html#h-5.2.2>


PointedEars

Reply With Quote
  #5  
Old   
Martin Honnen
 
Posts: n/a

Default Re: XHR und encoding - 10-25-2009 , 08:08 AM



Chris Seidel wrote:
Quote:
On Sun, 25 Oct 2009 12:08:21 +0100, Martin Honnen <mahotrash (AT) yahoo (DOT) de
wrote:

Dann sollte der Server den HTTP header
Content-Type: text/plain; charset=ISO-8859-1
senden. Woher sonst soll der Browser wissen, welche Kodierung die
Antwort hat?

Ist ISO-8859-1 nicht default, wenn nichts gesetzt ist?
Meines Wissens nicht. Browser kann man konfigurieren, welches "default
character encoding" sie benutzen, aber mir ist nichts bekannt, dass HTTP
selber eine Kodierung vorgibt.
Meines Wissens benutzt MSXML UTF-8 als default:
http://msdn.microsoft.com/en-us/library/ms762275(VS.85).aspx
besagt: "It assumes the default encoding is UTF-8, but can decode any
type of UCS-2 (big or little endian) or UCS-4 encoding as long as the
server sends the appropriate Unicode byte-order mark"

Und wenn ich
http://www.w3.org/TR/XMLHttpRequest/#text-response-entity-body richtig
verstehe, dann besagt Schritt 7 "If charset is null let charset be
UTF-8." auch da, dass UTF-8 als default benutzt wird, so sich in den
vorherigen Schritten kein Wert hat ermitteln lassen. Aber das ist eh bis
jetzt nur ein "working draft".


--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/

Reply With Quote
  #6  
Old   
Holger Jeromin
 
Posts: n/a

Default Re: XHR und encoding - 10-25-2009 , 11:47 AM



Martin Honnen schrieb am 25.10.2009 13:08:
Quote:
Chris Seidel wrote:
On Sun, 25 Oct 2009 12:08:21 +0100, Martin Honnen <mahotrash (AT) yahoo (DOT) de
Chris Seidel wrote:
Setze ich xmlhttp.overrideMimeType("text/plain; charset=ISO-8859-1");
klappt es.
Das können leider auch nicht alle Browser (mindestens ie6 nicht).

Quote:
Dann sollte der Server den HTTP header
Content-Type: text/plain; charset=ISO-8859-1
senden. Woher sonst soll der Browser wissen, welche Kodierung die
Antwort hat?
Ist ISO-8859-1 nicht default, wenn nichts gesetzt ist?
Meines Wissens nicht. Browser kann man konfigurieren, welches "default
character encoding" sie benutzen, aber mir ist nichts bekannt, dass HTTP
selber eine Kodierung vorgibt.
Meines Wissens benutzt MSXML UTF-8 als default:
http://msdn.microsoft.com/en-us/library/ms762275(VS.85).aspx
besagt: "It assumes the default encoding is UTF-8, but can decode any
type of UCS-2 (big or little endian) or UCS-4 encoding as long as the
server sends the appropriate Unicode byte-order mark"

Und wenn ich
http://www.w3.org/TR/XMLHttpRequest/#text-response-entity-body richtig
verstehe, dann besagt Schritt 7 "If charset is null let charset be
UTF-8." auch da, dass UTF-8 als default benutzt wird, so sich in den
vorherigen Schritten kein Wert hat ermitteln lassen. Aber das ist eh bis
jetzt nur ein "working draft".
In der Praxis wird von den Browsern (ie6+7, ff2, opera, webkit) utf8
angenommen.

--
Mit freundlichen Grüßen
Holger Jeromin

Reply With Quote
  #7  
Old   
Chris Seidel
 
Posts: n/a

Default Re: XHR und encoding - 10-25-2009 , 12:40 PM



On Sun, 25 Oct 2009 12:08:21 +0100, Martin Honnen <mahotrash (AT) yahoo (DOT) de>
wrote:

Quote:
Dann sollte der Server den HTTP header
Content-Type: text/plain; charset=ISO-8859-1
OK; so klappt es, danke.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.