ajax 與中文
20080825 shyong
今天在試寫第一個用 php 程序的簡單 ajax 應用時,在中文部分一直傳回亂碼,後來查 Google 才知,因為編碼原因,
- Server 端傳回時必須先告知編碼 ,即先送出 : header('Content-Type:text/html;charset=big5');
- Client 端傳送須先 URI 編碼 : var url = "url.php?name=" + encodeURIComponent(value);
Server 端測試可以,Client 等有用到再試
20080828 shyong
測試 Client 端送中文參數一直不行,後來在網上查到以下做法,測試後可行
- 在 Client 送參數時,不管是 Get 或 Post,都不要加編碼,即前面不要用 escape 或 encodeURIComponent 之類的編碼,直接送出
如下: Get => var url = "cl.php?hclass=" + hclass Post => request.send("hclass="+hclass); - 在 Server 加入 header('Content-Type:text/html;charset=big5');
$hclass=iconv( 'UTF-8', 'big5//IGNORE' , $hclass); - 我想應該是 Javascript 傳送是 utf-8 的格式,所以在 Server 端用 iconv 轉換編碼成 big5,再用 big5 格式送出就可以了
迴響
ajax 與中文 | 豬窩
Woah! I'm really loving the template/theme of this site.
It's simple, yet effective. A lot of times it's
difficult to get that "perfect balance" between usability and appearance.
I must say you've done a superb job with this. Also, the blog loads extremely fast for me on Opera.
Excellent Blog!
ajax 與中文 | 豬窩
Oh my goodness! Incredible article dude! Many thanks, However
I am experiencing difficulties with your RSS.
I don't understand why I cannot subscribe to it. Is there anyone else
having the same RSS problems? Anyone that knows
the solution will you kindly respond? Thanx!!
ajax 與中文 | 豬窩
Hey there, You have done an incredible job. I will certainly digg it
and personally suggest to my friends. I'm sure they will be benefited from this website.
ajax 與中文 | 豬窩
Hi there just wanted to give you a quick heads up
and let you know a few of the images aren't loading properly.
I'm not sure why but I think its a linking issue.
I've tried it in two different browsers and both show
the same outcome.
ajax 與中文 | 豬窩
Just desire to say your article is as amazing. The clearness in your
post is simply excellent and i could assume you are an expert
on this subject. Well with your permission allow me to grab your RSS feed to keep up to date
with forthcoming post. Thanks a million and
please carry on the gratifying work.