c00ce514錯誤,經過測試,我的是編碼錯誤,我的程序是用php寫的,這裡貼出使用php時的解決方法

1)先利用encodeURIComponent函數對查詢字符進行編碼,
同時設定header編碼方式為uft-8,
採用post方法,
由check.php處理請求

  1. ......(獲得XMLHTTPRequest對像 http_request)
  2.  var queryString = encodeURIComponent("username") 
  3.                          + "=" 
  4.                         + encodeURIComponent(str);
  5.         http_request.onreadystatechange = processRequest;
  6.         // 確定發送請求的方式和URL以及是否同步執行下段代碼
  7.         var contentType = "application/x-www-form-urlencoded; charset=utf-8";
  8.         // 確定發送請求的方式和URL以及是否同步執行下段代碼
  9.         http_request.open("post", 'check.php', true);
  10.         http_request.setRequestHeader("Content-Type", contentType);
  11.         http_request.send(queryString);



(2)check.php中處理代碼

  1. <?php
  2.  //使用iconv函數進行編碼轉換(utf-8-->gb2312),轉換後就可以進行相應的操作如比較
  3.  $username=iconv("utf-8", "gb2312", urldecode(@$HTTP_POST_VARS["username"]));
  4.  //echo 時因為是響應,所以要轉換回utf-8(gb2312-->utf-8)
  5.  if($username=="張三")
  6.         echo iconv("big5", "utf-8", "該用戶名已經被人使用,請選擇其他!");
  7.  else 
  8.        echo iconv("big5", "utf-8", "該用戶名可用");
  9.  ?>


這樣就可以正常顯示中文了

arrow
arrow
    全站熱搜

    Felix 發表在 痞客邦 留言(0) 人氣()