Ms7 Search
Google 搜尋 翻譯
calendar
« 九月 2024 »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
近期文章
文章分類
網站連結
Syndicate

« | »

ajax 與中文

2008-08-25 @ 21:38 in PHP, JavaScript, Sql

20080825 shyong

今天在試寫第一個用 php 程序的簡單 ajax  應用時,在中文部分一直傳回亂碼,後來查 Google  才知,因為編碼原因,

  1. Server 端傳回時必須先告知編碼 ,即先送出 :  header('Content-Type:text/html;charset=big5');
  2. Client  端傳送須先 URI 編碼 : var url = "url.php?name=" + encodeURIComponent(value);

Server 端測試可以,Client 等有用到再試

20080828 shyong

測試 Client 端送中文參數一直不行,後來在網上查到以下做法,測試後可行

  1. 在 Client 送參數時,不管是 Get 或 Post,都不要加編碼,即前面不要用 escape 或 encodeURIComponent 之類的編碼,直接送出
    如下: Get => var url = "cl.php?hclass=" + hclass   Post => request.send("hclass="+hclass);
  2. 在 Server 加入  header('Content-Type:text/html;charset=big5');
                        $hclass=iconv( 'UTF-8', 'big5//IGNORE' , $hclass);
  3. 我想應該是 Javascript 傳送是 utf-8 的格式,所以在 Server 端用 iconv 轉換編碼成 big5,再用 big5 格式送出就可以了

 

 

迴響

ajax 與中文 | 豬窩

Good blog you've got here.. It's hard to find high quality writing
like yours nowadays. I honestly appreciate people like you!

Take care!!

作者 Phone Psychic Readings @ 08:42, 2018-09-28

ajax 與中文 | 豬窩

Hi! This is my first comment here so I just
wanted to give a quick shout out and tell you I really enjoy reading your posts.
Can you recommend any other blogs/websites/forums that go over the
same topics? Thanks a ton!

作者 Darla @ 02:27, 2018-10-03

ajax 與中文 | 豬窩

Hi! I could have sworn I've been to this web site before but after looking at some
of the articles I realized it's new to me. Regardless, I'm definitely pleased I found it and I'll be bookmarking it and checking back regularly!

作者 soi keo @ 02:06, 2018-10-10

ajax 與中文 | 豬窩

Pretty nice post. I just stumbled upon your weblog and wished to
say that I've truly enjoyed surfing around your blog posts.
After all I'll be subscribing to your feed and I hope you write again soon!

作者 soi keo @ 12:59, 2018-10-18

ajax 與中文 | 豬窩

Да и сейчас такое время...выдают редиты только проверенным клиентам.

作者 www.iqfinance.ru/ @ 01:49, 2018-12-26
發表迴響
 authimage