En Thu, 25 Dec 2008 07:27:03 -0200, zxo102 <zxo...@gmail.com> escribió:
On 12月25日, 下午3时35分, "Chris Rebert" <c...@rebertia.com> wrote:
On Wed, Dec 24, 2008 at 11:29 PM, zxo102 <zxo...@gmail.com> wrote:
> Hi,
> I retrieve some info in Chinese from postgresql and assign it to a
> variable 'info' defined in javascript of a html page:
> var info = ['\xd6\xd0\xce\xc4','\xd6\xd0\xce\xc4','\xd6\xd0\xce
> \xc4']
> But I want it to be
> var info = ['中文','中文','中文']
> since in html pages (via javascript), the items in chinese out of the
> former :['\xd6\xd0\xce\xc4','\xd6\xd0\xce\xc4','\xd6\xd0\xce\xc4'] can
> not be displayed correctly when it is inserted into a html page. If
> the list is var info = ['中文','中文','中文'] , then everything works
> fine.
The html code is as follows
<html><head> <title> test </title></head><body>
<script language=javascript>
var row01 = (1, '\xd6\xd0\xce\xc4', '1334995555555')
var row02 = (2, '\xd6\xd0\xce\xc4', '3434343434343')
</script>
</body></html>
But the '中文' is '\xd6\xd0\xce\xc4'. When row01 and row02 is called
from somewhere,
'\xd6\xd0\xce\xc4' can not be displayed correctly as '中文' in html
environment.
You forgot to specify the page encoding, gb2312 presumably. If adding the
encoding does not help, I'd say the problem must reside on how you later
use row01 and row02 (your html page does not those variables for
anything). '中文' is the same as '\xd6\xd0\xce\xc4', and both javascript
and Python share the same representation for strings (mostly) so this
should not be an issue.
My PC is unable to display those characters, but I get "true" from this:
<html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset='gb2312'"><title> test </title></head>
<body><script
language=javascript>alert('中文'=='\xd6\xd0\xce\xc4')</script></body></html>
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list