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