It refuses to show me Swedish characters.I gather its something to do
with encoding.
Two types of data are in the documents I display using this. The first
type is straight text and here the Swedish characters only work if
they are keyed in code in my source documents.
Å = Å
Ä = Ä
Ö = Ö
å = å
ä = ä
ö = ö
If they are keyed in as normal characters they display strange output,
I can work around this problem by keying in the codes for these
characters.
However some data, peoples names etc are retrieved from the net from a
phpmyadmin mySQL server using php language. And all of these display
weird substitute characters instead of the Swedish characters.
Here is the code, what do I add and where do I add it to get Swedish
characters from the pages pulled in by ajax?
Any help greatly appreciated.
------------------------------------------------------
var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}
else
{
alert("Problem 1");
}
}
function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
document.getElementById('T1').innerHTML=xmlhttp.responseText;
}
else
{
alert("Problem 2:");
}
}
}
------------------------------------------------------
Garry Jones
Sweden
on 09/05/2010 03:11 PM GarryJones said the following:
> Two types of data are in the documents I display using this. The first
> type is straight text and here the Swedish characters only work if
> they are keyed in code in my source documents.
> Å = Å
> Ä = Ä
> Ö = Ö
> å = å
> ä = ä
> ö = ö
That is because you are not sending the text strings with the same
encoding as what is used in the page where you want to show the content
sent via AJAX. If the page is UTF-8, you need to encoded it as UTF-8 on
the server before sending.
Anyway, if you are setting the content using innerHTML, why don't you
just send it with HTML entities Å?
--
Regards,
Manuel Lemos
JS Classes - Free ready to use OOP components written in JavaScript
http://www.jsclasses.org/
--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---
Or to turn the question around, if he fixes the encoding issue, why
bother using HTML entities?
Get your code aligned when it comes to the charset, and all should be
in order. I'm actually amazed that ISO-8859-1 and other charsets are
still common, but that's probably due to bad defaults from Apache...
Sean
on 09/06/2010 04:03 AM Sean Kinsey said the following:
Maybe he is not using any encoding at all, so HTML entities always work
no matter what is the encoding the browser is assuming.
Or he sets a proper charset and we all live merrily ever after...
Solve the *right* problem.
Sean
Firstly, you need to know what encoding is in the content-type headers
the server is sending:
Content-Type:text/html; charset=utf-8
You can see this in:
Safari/Chrome: develop/webInspector/Resources/Response Headers
FireFox: tools/firebug/open Firebug/net/html/request/headers/response
headers
Because, no matter what you've got into
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
...
The headers prevail... always, except when you're loading it locally
(from a file:// url).
Secondly, you need to match the encodings: if the headers say ISO, you
must send the test encoded in ISO, if the headers say UTF-8, you must
send UTF-8 text.
That, or, as Manuel has told you, the &xxx; html entities will work
all the times, although this is not what I'd prefer to do.
--
Jorge.