Langauge Issue with DOM

A

Anees

Hi,

I want to display some germen text in my site.
and it is coming well when i have given content="text/html;
charset=utf-8" in meta Tag

But when i takes some data (as HTML) from server through AJAX and
insert it into a Div using innerHTML property,the characters are not
displaying well

Please help to find some solution

Regards,
Anees
 
G

GArlington

Hi,

I want to display some germen text in my site.
and it is coming well when i have given content="text/html;
charset=utf-8" in meta Tag

But when i takes some data (as HTML) from server through AJAX and
insert it into a Div using innerHTML property,the characters are not
displaying well

Please help to find some solution

Regards,
Anees

The page answering AJAX call should specify charset too...
 
M

Martin Honnen

Anees said:
But when i takes some data (as HTML) from server through AJAX and
insert it into a Div using innerHTML property,the characters are not
displaying well

Make sure your server-side code sends a HTTP Content-Type header with a
proper charset parameter e.g.
Content-Type: text/plain; charset=UTF-8
The charset parameter value to use depends entirely on how the data is
encoded, UTF-8 is just an example.
 
A

Anees

Make sure your server-side code sends a HTTP Content-Type header with a
proper charset parameter e.g.
Content-Type: text/plain; charset=UTF-8

I have added the line

header("Content-type: text/html; charset=UTF-8");

in my PHP server side file..
but still am not getting the characters right!!!
 
M

Martin Honnen

Anees said:
I have added the line

header("Content-type: text/html; charset=UTF-8");

in my PHP server side file..
but still am not getting the characters right!!!

Well you do not only have to set the charset parameter, you also have to
make sure the content your PHP sends is encoded that way. PHP can only
do Unicode with the help of extensions like iconv or mbstring. It has
limited support for some characters however using
<http://de3.php.net/utf8_encode> so assuming you tell the client the
content is UTF-8 encoded and you want to send German umlauts you need e.g.
echo utf8_encode("äöüÄÖÜß");
 
S

SAM

Anees a écrit :
Hi,

I want to display some germen text in my site.
and it is coming well when i have given content="text/html;
charset=utf-8" in meta Tag

But when i takes some data (as HTML) from server through AJAX and
insert it into a Div using innerHTML property,the characters are not
displaying well

In what charset are your html datas encoded ?

With which browser(s) does that happens ?

With my tries about Ajax on a server that does'nt send charset headers
I use only files written (coded ?) in utf-8

I have same problem as yours with files in utf-8 only with Safari which
wants absolutely to read them in iso-8859-1.
For him I inserts the xml declaration on top of files to call :
<?xml version="1.0" encoding="utf-8"?>
and that seems to fix the question.
 
T

Thomas 'PointedEars' Lahn

Martin said:
Well you do not only have to set the charset parameter, you also have to
make sure the content your PHP sends is encoded that way. PHP can only
do Unicode with the help of extensions like iconv or mbstring. It has
limited support for some characters however using
<http://de3.php.net/utf8_encode> so assuming you tell the client the
content is UTF-8 encoded and you want to send German umlauts you need
e.g. echo utf8_encode("äöüÄÖÜß");

That is only one half of the truth. What was said only applies if PHP is
pulling content from another resource that it needs to convert to a UTF
encoding. In any other case PHP scripts encoded in UTF-8 run seamlessly
without any extensions for that, provided that you use the above header() call.


PointedEars
 
A

Anees

With my tries about Ajax on a server that does'nt send charset headers
I use only files written (coded ?) in utf-8


First i have set the header in the to of PHP action file
header("Content-type: text/html; charset=UTF-8");
but it doesnt take any effect

Then i removed it and i converted all my data with
utf8_encode($germ_data);
Now it is working well..
I have same problem as yours with files in utf-8 only with Safari which
wants absolutely to read them in iso-8859-1.
For him I inserts the xml declaration on top of files to call :
<?xml version="1.0" encoding="utf-8"?>
and that seems to fix the question.

i am just getting whole the data from the server with responseText
and keeping all the data in a DIV with InnerHTML property..
So does i need to go for
<?xml version="1.0" encoding="utf-8"?>
in the page top?
 
T

Thomas 'PointedEars' Lahn

Anees said:
First i have set the header in the to of PHP action file
header("Content-type: text/html; charset=UTF-8");
but it doesnt take any effect

Of course not. A mere declaration does not suffice; for example, my saying
"The moon consists of green cheese. [psf 4.17]" does not make it so.
Then i removed it and i converted all my data with
utf8_encode($germ_data);
Now it is working well..

You have to do none or *both* of them to do it right. The first one only
declares the encoding of the data. The second one actually *changes* the
encoding of the data to the one previously declared.

If you don't declare the proper encoding, you are relying on the outcome of
guessing games on the part of the user agent.
i am just getting whole the data from the server with responseText
and keeping all the data in a DIV with InnerHTML property..
So does i need to go for
<?xml version="1.0" encoding="utf-8"?>
in the page top?

Usually not. An XML parser is required to recognize an UTF-8 encoded
resource without declaration.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,825
Members
47,371
Latest member
Brkaa

Latest Threads

Top