页面之间URL传递字符串escape进行编码

admin 发布时间:2014-09-08 分类:Web 阅读:4346次 添加评论

escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串,避免接受到的字符为乱码。当传递的字符串存在汉字或空格等字符时候可以使用escape进行编码,编码后可以使用 unescape() 对 escape() 编码的字符串进行解码。但ECMAScript v3 反对使用该方法,应用使用 decodeURI() 和 decodeURIComponent() 替代上面的两个函数。

例子:

function CheckUnique() {
   xmlHttp = GetXmlHttpObject()
   if (xmlHttp == null) {
       alert("Browser does not support HTTP Request")
       return false;
   }
   var BlockCode = $("#<%=txtBlockCode.ClientID%>").val()
   var url = "../../HttpHandler/CheckBlockUnique.ashx" + "?sid=" + Math.random();
   url = url + "&Num=" + escape(BlockCode);
   xmlHttp.onreadystatechange = stateChanged;
   xmlHttp.open("GET", url, true);
   xmlHttp.send(null);
}


关键字词: escape编码乱码

暂无留言

发表评论:

◎欢迎您的参与讨论。