url传递中文参数理解以及解决方案



使用两个js函数encodeURI() 和 encodeURIComponent()
encodeURIComponent() 这个方法是能够把url中符号都编码掉,比如?,/等
encodeURIComponent()主要用作传递返回url.

如果是英文编码成url的编码,需要encodeURI,如果是中文需要encodeURI(encodeURI(link))
因为  带中文url->英文化->真正编码成url

==============主页->内页,传递参数============
//获取返回的url
var backUrl = this.searchUrl();

var link = "analyze.inventory.InventoryStream.d?goodsId="+goodsId+"&specId="+specId+"&startDate="+startDate+"&endDate="+endDate+"&goodsName="+goodsName+"&backUrl="+encodeURIComponent(backUrl);
//dorado.MessageBox.alert(encodeURI(encodeURI(link)));
window.location.href=encodeURI(encodeURI(link));


==================内页,返回按钮=====================
var backUrl = '${request.getParameter("backUrl")}';
backUrl = decodeURIComponent(decodeURIComponent(backUrl));
//dorado.MessageBox.alert("正常的返回rul:"+backUrl);
backUrl="analyze.inventory.InventoryInfo.d"+encodeURI(encodeURI(backUrl));
//dorado.MessageBox.alert("backUrl:"+backUrl);
window.location.href=backUrl;

====================主页,获取参数============================
var catagoryId = '${request.getParameter("catagoryId")}';
var goodsCodeOrName= '${request.getParameter("goodsCodeOrName")}';
if(catagoryId!=null && catagoryId!=''){
                      dsSearchInventory.getData().set("catagoryId",catagoryId);
hasParam = true;
}

if(goodsCodeOrName!=null  && goodsCodeOrName!=''){
//dorado.MessageBox.alert("goodsCodeOrName:"+goodsCodeOrName);
dsSearchInventory.getData().set("goodsCodeOrName",decodeURI(decodeURI(goodsCodeOrName)));
hasParam = true;
}



http://www.javascripter.net/faq/escape.htm

你可能感兴趣的:(url传递中文参数解决方案)