ajax如何传中文参数乱码解决办法_PHP教程
Jul 13, 2016 am 10:54 AMajax如何传中文参数乱码解决办法 由于某种原因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
*/

인기 기사

인기 기사

뜨거운 기사 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Black Shark 휴대폰이 켜지지 않는 문제를 해결하는 방법을 알려주는 5가지 팁!

Call of Duty: Warzone 모바일 게임에서 중국어를 설정하는 방법

PHP로 txt 파일을 작성할 때 중국어 왜곡 문자를 해결하기 위한 팁

간단한 단계: VSCode의 중국어 인터페이스를 표시할 수 없는 문제를 해결합니다.
