zl程序教程

您现在的位置是:首页 >  后端

当前栏目

asp.net中在用ajax格式传递数据到aspx页面时出现乱码

NetASPAJAX 页面 格式 出现 乱码 aspx
2023-06-13 09:14:43 时间
 asp.net中在用ajax格式传递数据到aspx页面时有时会出现乱码,以下为解决方法

js中
复制代码代码如下:

XmlHttp.open("POST","test.aspx",false);
XmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
XmlHttp.send("QueryName="+escape(Queryname)+"&QuerySex="+escape(Querysex));

在test.aspx中
复制代码代码如下:

stringQueryName=HttpUtility.UrlDecode(Request.Params["QueryName"]);
stringQuerySex=HttpUtility.UrlDecode(Request.Params["QuerySex"]);