[OpenLayers-Users] character encoding

Tim Schaub tschaub at openplans.org
Thu Dec 13 11:41:19 EST 2007


Hey-

Arnd Wippermann wrote:
> Thanks for the reply. 
> 
> But the problem is, that I use ajax to request GetFeatureInfo on a MapServer
> WMS. In reponse I get ISO-8859-1 encoding, but ajax only understand UTF-8

This is not correct (that "ajax only understands utf-8").  If your 
server does not correctly set the character encoding in the header

Content-Type: text/html; charset=ISO-8859-1

then your browser makes some guesses about the character set.  With 
html, your last chance to correctly set the character encoding is to add 
a meta tag like this:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">

Your original page should have this tag if it is not served up with the 
correct header.  When you request additional data with XMLHttpRequest, 
the character encoding needs to be set in the headers.  So, make a 
GetFeatureInfo request to your WMS and confirm that you get the 
following header:

Content-Type: text/html; charset=ISO-8859-1

If not, then there is nothing that OpenLayers (or your browser) can do 
to correct it.

Tim

> (Questionmarks instead of german umlaute, clienside no way to translate the
> questionmarks to the correct letter). So I have to use a serverside script
> to translate the data from one encoding to UTF-8 or using some hack and
> escape the response.
> 
> Instead of using ajax to get the data, the way is using ajax via a
> serverside script to get the data. I have to involve a second server (my
> server) to get the data in a form, which I can clientside translate to the
> right.
> 
> If you know a simplier way to get äöü's, please help.
> 
> Mit freundlichen Grüssen
> 
> Arnd Wippermann
> http://gis.ibbeck.de/ginfo/
> 
> 
> 
>  
> 
> -----Ursprüngliche Nachricht-----
> Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
> Auftrag von Tim Schaub
> Gesendet: Mittwoch, 12. Dezember 2007 20:03
> An: users at openlayers.org
> Betreff: Re: [OpenLayers-Users] character encoding
> 
> This thread is a bit old now, but I thought I'd send a quick addition to it.
> 
> To correctly deal with character encoding given asynchronously loaded data,
> you should declare the character encoding in your html as well.
> 
> For example, if you use utf-8 in some remotely loaded script, json, or
> whatever, then your application (the html delivered by the request for your
> original url) should declare (in the head of your html):
> 
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
> 
> This lets the browser know how to interpret any subsequently loaded
> (asynchronous) data that might be rendered in the same page.
> 
> Tim
> 
> Arnd Wippermann wrote:
>> Hi,
>>
>> To declare your proxy, you set something like this:
>>  OpenLayers.ProxyHost = "http://localhost/cgi-bin/proxy.cgi?url=";
>>
>> If you use this function, the above script will used to retrieve the 
>> data  OpenLayers.loadURL(url, '', this, setHTML);
>>
>> If you have the OpenLayers source, there is a python proxy script 
>> proxy.cgi in the examples directory.
>>
>> You have to include this in your web server environment. Look at the 
>> OpenLayers mailling list for further informations.
>>
>> If this is running, I have used a trick to get special characters. 
>> There seems no easy way in python to translate special character into 
>> html entities. So I escape in the proxy-script the response to the 
>> ajax call and after that unescape the response from the ajax-function.
>>
>> proxy-script, change row : print y.read() to: print 
>> urllib.quote(y.read())
>>
>> html-file, change: response.responseText; to:
>> unescape(response.responseText);
>>
>> I have this tested locally with my apache server and it delivers the 
>> äöüs etc..
>>
>> Mit freundlichen Grüssen
>>
>> Arnd Wippermann
>> http://gis.ibbeck.de/ginfo/
>>
>>
>>
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: users-bounces at openlayers.org 
>> [mailto:users-bounces at openlayers.org] Im Auftrag von R. Ortner
>> Gesendet: Mittwoch, 5. Dezember 2007 11:07
>> An: users at openlayers.org
>> Betreff: Re: [OpenLayers-Users] character encoding
>>
>>
>> Thanks for your replay and i basically know what u mean but I have 
>> absolutely no idea how such a proxy script looks like, how i put it 
>> into my Application and how do i call it?
>>
>> would be very grateful for explizit examples (couldnt find a 
>> proxy-script in the link below)
>>
>>
>>
>> Arnd Wippermann wrote:
>>> Hi,
>>>
>>> If you use OpenLayers.loadURL(url, '', this, setHTML); like in the ol 
>>> example, then your request use Ajax. Therefor you need a proxy-script.
>>> In this script you can change the special char to html entities.
>>>
>>> With asp I use this function:
>>>  
>>> Response.Write server.HTMLEncode(objXmlHttp.responseText)
>>>
>>>
> http://gis.ibbeck.de/ginfo/apps/olexamples/sphericalmercator/wms_getfeature.
>>> html
>>>
>>> Mit freundlichen Grüssen
>>>
>>> Arnd Wippermann
>>> http://gis.ibbeck.de/ginfo/
>>>
>>>
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: users-bounces at openlayers.org
>>> [mailto:users-bounces at openlayers.org] Im Auftrag von R. Ortner
>>> Gesendet: Dienstag, 4. Dezember 2007 12:15
>>> An: users at openlayers.org
>>> Betreff: [OpenLayers-Users] character encoding
>>>
>>>
>>> hi,
>>>
>>> I´ve still trouble with my special character encoding.
>>>
>>> -The database is in Latin1 and in Win-1252 (both capable of special 
>>> caracters like ö,ä,ü,²,...) -the OL.php file is defined in the head 
>>> sectoin as Iso-8859-1 -the template.html specified in the mapfile is 
>>> defined as
>>> Iso-8859-1
>>>
>>> when I call the GetFeatureInfo request in the browser it is displayed 
>>> correctly (also in qgis or gvsig), when i call it witin the OL 
>>> application no special character is displayed(only ? as symbols) not 
>>> even the special characters in "plain" text in the template file. (I 
>>> have a table, in one row i wrote some text like "länge" in the second 
>>> row is the GetInfoRequest from the database) Then it writes "l?nge"
>>> instead of "länge"
>>>
>>> so i don´t think the database is responsible for that and not the 
>>> template file specified in Iso-8859-1!
>>>
>>> is there a way to tell the mapserver to send the characters in
>>> Iso-8859-1 or something in OL to define?
>>>      Because either the mapserver send it wrong or it is displayed 
>>> wrong by OL.
>>>
>>> Or can I somehow send the encoding with the getFeatureInfo request?
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/character-encoding-tf4942492.html#a14148746
>>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>>
>> --
>> View this message in context:
>> http://www.nabble.com/character-encoding-tf4942492.html#a14168481
>> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>>
>>
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 
> !DSPAM:4033,4760636f303711637810514!
> 




More information about the Users mailing list