APs. NET and mvc3 solve the Ajax garbled problem in jquery

Source: Internet
Author: User
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

 

  1. $ (Document). Ready (function (){
  2. // Alert (encodeuri ("I "));
  3. $. Ajax ({URL:"A. php? A = "+ encodeuricomponent (" we "),
  4. Success:Function (re ){
  5. Alert (re );
  6. },
  7. Data :{"B": "We "},
  8. Error:Function (R, R1, R2 ){
  9. Alert (1 );
  10. }
  11. });
  12. });

 

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!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.