The encodeuricomponent () function can encode a string as a URI component. From http://blog.csdn.net/allsharps/article/details/6875419
Solve the Problem of Ajax garbled characters in jquery
-
- $ (Document). Ready (function (){
-
- // Alert (encodeuri ("I "));
-
- $. Ajax ({URL:"A. php? A = "+ encodeuricomponent (" we "),
-
- Success:Function (re ){
-
- Alert (re );
- },
-
- Data :{"B": "We "},
-
- Error:Function (R, R1, R2 ){
-
- Alert (1 );
-
- }
-
- });
- });
The data in the post form is always normal, but if the URL contains Chinese characters, the serverProgramGarbled characters will be received, such as/a. php? A = Chinese, this time if the server program uses gb2312 is normal, the use of UtF-8 garbled,
Solution: All pages use UTF-8. When Ajax is submitted, the Chinese characters in the URL are encoded (encodeuricomponent ("we"),), and then submitted without any problem, it is not intuitive for users to view URLs.
If you want to use it in a URL, you may need to judge the URL in the server program. If there are two-byte characters, you can perform gb2312 decoding.
Really!