服務器端:
Server.UrlEncode()方法對Url進行編碼
Server.UrlDecode()方法 對url進行解碼
Js方法:
escape() 函數可對字符串進行編碼;
unescape() 函數可對字符串進行解碼;
定義和用法
unescape() 函數可對通過 escape() 編碼的字符串進行解碼。
定義和用法
escape() 函數可對字符串進行編碼,這樣就可以在所有的計算機上讀取該字符串。
簡單例子:
js編碼:
1 Var name= escape ($(“#txtname”).value()); 2 var strurl =login.aspx+ "?opt=add&companyname=" + name ; 3 $.ajax({ 4 type: "POST", 5 cache: true, 6 url: strurl, 7 data: "opt=skip", 8 success: function (json) { 9 //成功方法 10 }, 11 error: function (e) { } 12 });
解碼:服務器端的解碼簡單:
1 String name= Server.UrlDecode(Request.QueryString["companyname "].ToString());