客戶端用js函數encodeURI()對中文字符進行兩次編碼,服務器端采用URLDecoder類對客戶端傳輸過來的中文字符進行UTF-8格式的解碼。
客戶端代碼:
$.ajax({
? ? ? ? ? ? ? ? ? ? ? ? type: "post",
? ? ? ? ? ? ? ? ? ? ? ? url: "../?id=" + encodeURI(encodeURI($("張三風")),
? ? ? ? ? ? ? ? ? ? ? ? success: function (msg) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? alert(msg);?
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? });
$.ajax({ ?
? ? ? type: "post", ?
? ? ? url: "createNewGroup.action", ?
? ? ?data:"name="+encodeURI(encodeURI("張三")), ?
? ? ? success: function(msg){ ?
? ? ? ? ? ?alert(msg); ?
? ? ?} ?
? ? });
服務器端對接收到的值進行解碼Server.UrlDecode(),服務器端代碼:
public string IsThisMemberName(string id) {
? ? ? ? ? ? string name = Server.UrlDecode(id);
? ? ? ? ? ? return name;
? ? ? ? }
decodeURI 方法:返回一個已編碼的統一資源標識符 (URI) 的非編碼形式。function decodeURI(URIstring : String) : String
decodeURIComponent 方法:返回統一資源標識符 (URI) 的一個已編碼組件的非編碼形式。
function decodeURIComponent(encodedURIString : String) : String
BTW:C#中對URL編碼的方法。。。
編碼:Server.UrlEncode(string)
解碼:Server.UrlDecode(string) 前面三種客戶端編碼都可以用這個方法在后臺解碼。
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!