转:http://blog.sina.com.cn/s/blog_6013f6620100wss4.html
?
一. 传递中文参数
function insertDetails(value){
var url = "<%=request.getContextPath()%>/bargainNewMaterialsAction.do?formAction=insertPlanDetail&details="+encodeURI(encodeURI(document.getElementByIdx_x("details").value));
createXMLHttpRequest();
XMLHttpReq.onreadystatechange = getFinsh;
XMLHttpReq.open("post",url , false);
XMLHttpReq.send(null);
}
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
XMLHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject){
try
{
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try{
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e) {
}
}
}
}
后台获取:
String materialsCodes = URLDecoder.decode(request.getParameter("details"),"utf-8");
二. 传递特殊字符参数,如 ? & 等
function financeProcess(){
var seqs = document.getElementsByName("sepType");
var sepValue;
for(var i=0;i<seqs.length;i++){
if(seqs[i].checked)
sepValue=seqs[i].value;
}
var url = "<%=request.getContextPath()%>/bargainNewMaterialsAction.do?formAction=financeProcess";
createXMLHttpRequest();
XMLHttpReq.onreadystatechange = getFinsh;
XMLHttpReq.open("post", url, false);
XMLHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //send 参数时此行必须有
XMLHttpReq.send("sapNo="+document.getElementByIdx_x("sapNo").value
+"&menu="+escape(encodeURIComponent(document.getElementByIdx_x("menu").value))
+"&public="+ escape(encodeURIComponent(document.getElementByIdx_x("public").value))
+"&sepType="+sepValue);
}
后台获取:
String menuUrl =?URLDecoder.decode(request.getParameter("menu"),"utf-8");
String publicUrl = URLDecoder.decode(request.getParameter("public"),"utf-8");