php转码函数和xmlhttp的协作

1.概要
若返回是UTF-8,用responseText接收;
若返回EUC-CN(GB2312),用responseBody接收,并用bytes2BSTR()转码
如果返回的是NCR,则无关xmlhttp接收属性,均可正常显示

2.后台程序的编码方式
后台处理程序若是用非UTF-8编码保存,则需要将其输出字符串用
mb_convert_encoding([str], “UTF-8″ [, mixed from_encoding])
编码为UTF-8,才可用reponseText接收

后台处理程序若用UTF-8编码保存,则需要
mb_convert_encoding([str], “EUC-CN” [, mixed from_encoding])
编码为GB2312,才能用responseBody转码接收

3.前台程序的编码方式
前台页面的编码方式与responseText/responseBody返回内容的编码方式无关,
即前台总能正常显示返回内容

无论前台页面何种方式编码,经过xmlhttp方式传递后的编码总为gb2312(EUC-CN)

4.提交时的处理方法
post提交时
需要用url编码(URLEncoding)

 var oReq = new ActiveXObject(”Microsoft.XMLHTTP”);
 var strA = URLEncoding(”a=” + frm.txt1.value + ‘&b=’ + frm.txt2.value);
 oReq.open(”POST”, “xmlhttp_post_process.htm”, false);
 oReq.setRequestHeader(”Content-Length”, strA.length);
 oReq.setRequestHeader(”CONTENT-TYPE”, “application/x-www-form-urlencoded”);
 oReq.send(strA);

后台才能用mb_convert_encoding编码成NCR形式:
mb_convert_encoding([str], “HTML-ENTITIES”, “EUC-CN”)

EUC-CN(GB2312)为处理程序默认的编码方式

get提交时,可无需url编码

相关文章

0 Responses to “php转码函数和xmlhttp的协作”


  1. No Comments

Leave a Reply