首页 > 代码库 > AJAX在Post中文的时候乱码的解决方法

AJAX在Post中文的时候乱码的解决方法

加上设置字符编码的方法: 
response.setHeader("charset","gb2312"); 

******************************************** 
看到的说明原文如下: 

用AJAX来GET回一个页面时,RESPONSETEXT里面的中文多半会出现乱码,这是因为xmlhttp在处理返回的responseText的时候,是把resposeBody按UTF-8编码进解码考形成的,如果服务器送出的确实是UTF-8的数据流的时候汉字会正确显示,而送出了GBK编码流的时候就乱了。解决的办法就是在送出的流里面加一个HEADER,指明送出的是什么编码流,这样XMLHTTP就不会乱搞了。 

PHP:header(‘Content-Type:text/html;charset=GB2312‘); 
ASP:Response.Charset("GB2312") 
JSP:response.setHeader("Charset","GB2312"); 

<iframe id="google_ads_frame2" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1399317177&flash=0&url=http%3A%2F%2Fwww.cnblogs.com%2Franzige%2Fp%2F3709335.html&dt=1399317180913&shv=r20140429&cbv=r20140417&saldr=sb&prev_slotnames=4356862740&correlator=1399317180788&frm=20&ga_vid=429972749.1397695120&ga_sid=1399310453&ga_hid=608278425&ga_fc=1&u_tz=480&u_his=279&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=tahoma&dfs=12&adx=0&ady=695&biw=314&bih=74&eid=317150304&oid=3&rx=0&eae=0&docm=9&vis=0&fu=0&ifi=2&xpc=FFVL3GRPdP&p=http%3A//www.cnblogs.com&dtd=45" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame2" marginWidth="0" scrolling="no" hspace="0"></iframe><iframe id="google_ads_frame3" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1399317177&flash=0&url=http%3A%2F%2Fwww.cnblogs.com%2Franzige%2Fp%2F3709335.html&dt=1399317180965&shv=r20140429&cbv=r20140417&saldr=sb&prev_slotnames=4356862740%2C8660799060&correlator=1399317180788&frm=20&ga_vid=429972749.1397695120&ga_sid=1399310453&ga_hid=608278425&ga_fc=1&u_tz=480&u_his=279&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=tahoma&dfs=12&adx=304&ady=945&biw=314&bih=74&eid=317150304&oid=3&rx=0&eae=0&docm=9&vis=0&fu=0&ifi=3&xpc=9dPwI9dvZn&p=http%3A//www.cnblogs.com&dtd=45" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame3" marginWidth="0" scrolling="no" hspace="0"></iframe>