Rumah  >  Artikel  >  pembangunan bahagian belakang  >  ajax如何传中文参数乱码解决办法_PHP教程

ajax如何传中文参数乱码解决办法_PHP教程

WBOY
WBOYasal
2016-07-13 10:54:01880semak imbas

ajax如何传中文参数乱码解决办法 由于某种原因ajax默认就是uft-8的编码,那么我们使用一gbk就容易出现乱码的问题,下面我们就来告诉你php ajax乱码的解决方法吧。

ajax如何传中文参数乱码解决办法
由于某种原因ajax默认就是uft-8的编码,那么我们使用一gbk就容易出现乱码的问题,下面我们就来告诉你php教程 ajax乱码的解决方法吧。
传递中文参数,然后修改数据库教程的。

<script><br /> var url="admin/ajaxmodify.php?"+key+"=";<br /> url+=encodeuricomponent(encodeuricomponent(value));<br /> xmlhttp.open("get",url,true);<br /> xmlhttp.send(null);<br /> </script>
参数是中文encodeuricomponent这个方法必须调用两次
*/

function utf8rawurldecode ($source) {
  $decodedstr = "";
  $pos = 0;
  $len = strlen ($source);
  while ($pos   $charat = substr ($source, $pos, 1);
  if ($charat == '%') {
  $pos++;
  $charat = substr ($source, $pos, 1);
  if ($charat == 'u') {
  // we got a unicode character
  $pos++;
  $unicodehexval = substr ($source, $pos, 4);
  $unicode = hexdec ($unicodehexval);
  $entity = "". $unicode . ';';
  $decodedstr .= utf8_encode ($entity);
  $pos += 4;
  }
  else {
  // we have an escaped ascii character
  $hexval = substr ($source, $pos, 2);
  $decodedstr .= chr (hexdec ($hexval));
  $pos += 2;
  }
  } else {
  $decodedstr .= $charat;
  $pos++;
  }
  }
  return $decodedstr;
}


/*
注:js中,在使用字符转码的时候,推荐使用 encodeuricomponent() 或者 encodeuri(),而非escape()。原因在于,escape() 只是为 ascii字符 做转换工作,转换成的 %unnnn 这样的码,如果要用更多的字符如 utf-8字符库就一定要用 encodeuricomponent() 或 encodeuri() 转换才可以成 %nn%nn 这的码才可以。

js:encodeuricomponent —— decodeuricomponent;php: rawurlencode —— rawurldecode


*/

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632362.htmlTechArticleajax如何传中文参数乱码解决办法由于某种原因ajax默认就是uft-8的编码,那么我们使用一gbk就容易出现乱码的问题,下面我们就来告诉你php...
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn