//If the transmission parameters are given directly, garbled characters will be generated!
Copy code The code is as follows:
http_request.open("POST",url,true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send("action=" +strName+"&val="+val); //If the value of val is Chinese, garbled characters will be generated
//The solution is simple: use the escape(string) function in javascript
Copy code The code is as follows:
http_request.open("POST",url,true);
http_request. setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send("action="+strName+"&val="+escape(val)); //Value of val Chinese characters will not be garbled
The simplest solution to the Chinese garbled characters in the ResponseText GET returned in AJAX
When using AJAX to GET back a page, the Chinese characters in the RESPONSETEXT will most likely be garbled. , this is because when xmlhttp processes the returned responseText, it encodes the resposeBody into UTF-8 and decodes it. If the server sends a UTF-8 data stream, the Chinese characters will be displayed correctly, and GBK will be sent. It gets messed up when encoding the stream. The solution is to add a HEADER to the sent stream to indicate what encoding stream is sent, so that XMLHTTP will not mess up.
Copy code The code is as follows:
PHP:header('Content-Type: text/html;charset= GB2312');
ASP:Response.Charset("GB2312")
JSP:response.setHeader("Charset","GB2312");
http://www.bkjia.com/PHPjc/319406.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319406.htmlTechArticle//If the transmission parameters are given directly, garbled characters will be generated! Copy the code as follows: http_request.open( "POST",url,true); http_request.setRequestHeader('Content-Type', 'applicatio...