Juquey 实战总结
例子:
gb2312.html
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <SCRIPT LANGUAGE="JavaScript" src="js/jquery-1.2.4.js"></script>
- <SCRIPT LANGUAGE="JavaScript">
- <!--
- $(document).ready(function(){
- $("#btn").click(function(){
- $.get("php/gb2312.php",function(data){
- $("#content").html(unescape(data));//这里unescape一下就可以了
- })
- });
- });
- //-->
- </SCRIPT>
- <title>无标题文档</title>
- </head>
- <body>
- <div ID="btn">获得ajax中文</div>
- <div ID="content"></div>
- </body>
- </html>
gb2312.php
- <?
- echo escape(" GB2312中文");
- function escape($str) {
- preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r);
- $ar = $r[0];
- foreach($ar as $k=>$v) {
- if(ord($v[0]) < 128)
- $ar[$k] = rawurlencode($v);
- else
- $ar[$k] = "%u".bin2hex(iconv("GB2312","UCS-2",$v));
- }
- return join("",$ar);
- }
- ?>