ajax传递中文参数到C#后台乱码
程序员文章站
2022-03-02 11:45:06
...
使用ajax传递中文参数到C#后台乱码的问题
js请求时进行二次编码:
var name = encodeURI(encodeURI("xxx"));
var url = "/Movies/GetMovieName?name=" + name;
$.get(url,{}, function () {}, "json")
var name = encodeURI(encodeURI("xxx"));
var url = "/Movies/GetMovieName?name=" + name;
$.get(url,{}, function () {}, "json")
C#后台解码:
public void GetMovieName(string name)
{
//HttpUtility.UrlDecode 方法
name = System.Web.HttpUtility.UrlDecode(name);
//Server.UrlDecode 方法
name = Server.UrlDecode(name);
}
GetMovieName(Request.From["container"].ToString())
public void GetMovieName(string name)
{
//HttpUtility.UrlDecode 方法
name = System.Web.HttpUtility.UrlDecode(name);
//Server.UrlDecode 方法
name = Server.UrlDecode(name);
}
例:GetMovieName(Request.From["container"].ToString())