您的位置:首页 > 其它

解决domino 中用ajax 时 send的中文参数出现乱码问题

2011-04-27 17:54 633 查看
var url="http://127.0.0.1/test/test.nsf/testAgent?openagent";
function ajax_keyword(url) {
xmlhttp = createXmlHttpRequest();
xmlhttp.onreadystatechange = handleSearchSuggest;
xmlhttp.open("post",url, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=GB2312");
xmlhttp.send("keyword=" + keyword.value);
}
结果在domino代理中获取 send过去的参数“keyword” 中文出现乱码,怎么处理??
解决方法:
xmlhttp.send("keyword=" + keyword.value);
在js代码中用encodeURIComponent()对参数keyword做转码,即:改成 xmlhttp.send("keyword=" + encodeURIComponent(keyword.value));
然后在接受的代理
再用 Evaluate 去执行公式用 @URLDecode 对传递进来的参数再次转码 ,就可以得到中文参数
dim s as new notessession
dim cdoc as notesdocument
Set cdoc =s.DocumentContext
Dim queryAr As Variant
queryAr=Evaluate(|@URLDecode("Domino";Request_Content)|,cdoc)’用domino 字符编码对url参数解码
说明:
encodeURIComponent是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持(form中的编码方式和当前页面编码方式相同)
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: