Jquery's powerful functions have become more and more popular among many friends. However, Ajax is a little too difficult to take care of the feelings of the Chinese people.
Data Transfer Encoding only supports UTF-8, although it is a globally unified code, but also consider the Chinese name local website encoding problem
In addition, on the sending end of jquery, no matter whether you have set the program-level encoding or page-level encoding, jquery uses UTF-8 encoding to pass through
Some websites are operating a long event, it is indeed a little difficult to completely modify the UTF-8, good complaints sent here, below is a solution example written by myself
Hope to help you.
Principle:
Use the escape method on the ajax sender. Then use the unescape Method for conversion at the receiving end
Example:
Gb2312.html
- <Html>
- <Head>
- <MetaHttp-equiv = "Content-Type"Content = "text/html;Charset = gb2312" />
- <SCRIPTLANGUAGE = "JavaScript"Src = "js/jquery-1.2.4.js"> </script>
- <SCRIPTLanguage = "JavaScript">
- <! --
- $ (Document). Ready (function (){
- $ ("# BTN"). Click (function (){
- $. Get ("PHP/gb2312.php", function (data ){
-
- $ ("# Content" ).html (unescape (data); // you can click unescape here.
-
- })
-
- });
- });
- //-->
- </SCRIPT>
- <Title> untitled document </title>
- </Head>
-
- <Body>
- <DivID = "btn"> get ajax Chinese </div>
- <DivID = "content"> </div>
-
- </Body>
- </Html>
Gb2312.php
- <?
- EchoEscape ("GB2312 Chinese");
- FunctionEscape ($ Str){
- Preg_match_all ("/[\ X80-\ xff]. | [\ x01-\ x7f] +/", $ str, $ r );
- $ Ar=$ R [0];
- Foreach ($ arAs$ K => $ v){
- If (ord ($ v [0])<128)
- $ Ar [$ k]=Rawurlencode ($ V );
- Else
- $ Ar [$ k]="% U". bin2hex (iconv ("GB2312", "UCS-2", $ v ));
- }
- ReturnJoin ("", $ Ar );
- }
- ?>