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

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:19   1720   0
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
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP