Ajax garbled Solution

Source: Internet
Author: User

Many beginnersAjaxAll of your friends will meetAjax garbledWhy Is Ajax garbled? How can we solve the problem of Ajax garbled characters? Are we looking at it?Ajax principlesWhat about it? Don't worry. Let's first look at the cause of Ajax garbled characters.

Very simple. Most JS frameworks use UTF-8. Now I understand why Ajax Garbled text occurs. How can we solve Ajax Garbled text? Two methods.

 

1. Only change the client's JsCode, Do not change the server code, the default JS only read the UTF-8 will not generate Ajax garbled:
1, if the server side of the page code is UTF-8, then the client directly with temp1 = XMLHTTP. responsetext to receive, will not produce garbled, because JS by default is read UTF-8 encoding.
2. If the server-side Page code is gb2312, the client must first use temp1 = XMLHTTP. responsebody receives the binary content returned by the server, and then uses a function to convert the binary into UTF-8 encoding, so that the contents of the client JS will not generate Ajax garbled.

2. Modify the server code. The server specifies the client to read the page in some encoding.
1. In JSP code: Response. setheader ("charset", "gb2312 ″);
2. in PHP code: Header ("Content-Type: text/html; charset = gb2312 ″);
3. In ASP code: Response. charset ("gb2312 ″)

 

The solution is simple. If you don't want to encounter Ajax garbled characters, simply use UTF-8. 126 Furniture Materials network

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.