1. 程式人生 > >EasyUI入門6 傳遞中文引數值避免亂碼

EasyUI入門6 傳遞中文引數值避免亂碼

前臺html寫法

DisciplineName:encodeURIComponent(row.專業名稱),
PurchaseNumber:encodeURIComponent($('#PurchaseNumber').textbox('getValue'))

後臺c#寫法

HttpUtility.UrlDecode(context.Request["DisciplineName"].ToString()); //中文解碼
HttpUtility.UrlDecode(context.Request["PurchaseNumber"].ToString()); //中文解碼

在ajax域內,設定字符集為UTF-8

$.ajax({
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        ……
});

html頁面也要設定字符集為UTF-8

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    ……
</head>