Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 942
  • Last Modified:

javascript pass Chinese characters fails

I generated a javascript code which is called from the brwoser.

When I check inside the IDE, everything looks good

var LeftBarcoalHtml = new Ext.ux.Html({
      width:60,
      value: '¿ ¿',
      name: 'LeftBar_coal',
      id: 'home_LeftBar_coal_id'
});

but when it arrived FF, the display becomes '? ?". I used Firebug to take a look at the javascript, it says

var LeftBarcoalHtml = new Ext.ux.Html({
width:60,
value: '? ?',
name: 'LeftBar_coal',
id: 'home_LeftBar_coal_id'
});

I tried playing with view -> character encoding -> Chinese Simplified (GB2312), but made no difference.

Is there something you need to declare to make the Chinese char show up in the browser properly?

note: happens here too. when I paste the Chinese char into the question, it looked good. Once submitted it becomes inverse ? like you see here.
0
bhomass
Asked:
bhomass
  • 4
  • 4
1 Solution
 
leakim971PluritechnicianCommented:
Try \uABCD where abcd is the unicode value of your character

http://www.khngai.com/chinese/charmap/tbluni.php?page=0

example : value: '\u4EE0 \u4EEf',
0
 
bhomassAuthor Commented:
I don't understand something.

when I copy/paste the Chinese characters, they are not in unicode form. They simply show up as Chinese characters. How do I tell what encoding is used?

to use your notation with \u, it would mean having to find the unicode representation from these Chinese characters, is that right? What api will allow me to do that? copied Chinese characters -> unicode
0
 
leakim971PluritechnicianCommented:
>How do I tell what encoding is used?
Use the meta tag but the best is to conserv utf-8 and use unicode values when needed

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

>to use your notation with \u, it would mean having to find the unicode representation from these Chinese characters, is that right?
right

>What api will allow me to do that?
I see a tools here :
http://weber.ucsd.edu/~dkjordan/resources/unicodemaker.html
Right click on the page, choose view source and check the gettem function
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
bhomassAuthor Commented:
I found out more.

The characters are in GBK. I added that charset in the html. made no difference.  the problem is not there.

The characters are passed up in json. When I check the output in my IDE, I can see that the chinese characters are properly included in the json string. on the browser side, I use Firefox to view the received json string, and already it shows that the Chinese characters have been converted to non-sense string, like '?????". by the time the json gets decoded in the js lib, the values remains as non-sense.

Anyone know why Firebug would already have mis-interpreted the json string?
0
 
leakim971PluritechnicianCommented:
it's not firebug, it's the way your program don't use the same encoding
use UTF8 everywhere and this type of issue left, else use \uABCD
for example on server side with PHP :

echo json_encode($a, JSON_UNESCAPED_UNICODE);

http://php.net/manual/en/function.json-encode.php
0
 
leakim971PluritechnicianCommented:
everywhere, I mean :

browser(client) and database(server side)
0
 
bhomassAuthor Commented:
hey, I found it.

I had to declare charset in the servlet response.

resp.setContentType("text/xml; charset=GBK");
0
 
bhomassAuthor Commented:
Not a direct answer, but on the right track
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now