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