解决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
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
相关文章推荐
- 解决ajax传递中文参数,出现乱码的问题
- ajax post 提交中文java后台获取参数出现乱码解决方法
- 从js向Action传中文参数出现乱码问题的解决方法
- JSP页面中超链接传递中文参数出现乱码问题解决方法
- 解决 jsp传中文参数到servlet出现乱码问题
- escape函数解决js中ajax传递中文出现乱码问题
- 彻底解决get显示提交时,参数中包含中文时出现乱码的问题
- 使用AJAX传递中文参数,在后台接受出现乱码问题
- get请求时候参数中含有“中文”字段出现乱码问题的原因和解决方法
- ajax中出现中文乱码和缓存的问题的解决方法
- 从js向Action传中文参数出现乱码问题的解决方法
- SpringMVC 解决Controller里获取请求参数出现中文乱码问题
- 从js向Action传中文参数出现乱码问题的解决方法
- 用ajax传递参数时遇到中文乱码问题的解决方法
- 解决中文参数出现的乱码问题
- 解决ASP.NET带中文参数出现乱码的问题
- 从js向Action传中文参数出现乱码问题的解决方法
- 解决SpringMVC Controller 接收页面传递的中文参数出现乱码的问题
- struts+ajax中文参数乱码解决问题
- JSP解决ajax使用$.get()方式提交中文出现乱码问题