javascript 转URL传中文参数乱码问题解决办法
来源:互联网 发布:电脑安装软件被禁止 编辑:程序博客网 时间:2024/06/05 17:31
Javascript 部份:
<script type="text/javascript">
function scriptUpdate(controlid) {
try {
var myxmlhttp = false;
if (window.XMLHttpRequest) {
myxmlhttp = new XMLHttpRequest();
} else {
myxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
myxmlhttp.onreadystatechange = function() {
if (myxmlhttp.readyState < 4) {
//document.getElementById("myDiv").innerHTML = "数据读取中....";
}
if (myxmlhttp.readyState == 4 && myxmlhttp.status == 200) {
//document.getElementById("myDiv").innerHTML = myxmlhttp.responseText;
}
}
var str = controlid.id.replace("etxt", "").replace("eres", "");
var txt_Description = document.getElementById("etxt" + str).value;
var txt_Remarks = document.getElementById("eres" + str).value;
myxmlhttp.open("Get", "Default2.aspx?Remarks=" + encodeURIComponent(txt_Remarks) + "&Description=" + encodeURIComponent(txt_Description) + "&key=" + str + "&isNaM=" + Math.random(), true);
myxmlhttp.send();
} catch (e) {
alert("Ajax错误!")
}
}
</script>
后台代码部份:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (string.IsNullOrEmpty(Request["key"]))
{
SetTree(0);
}
}
if (!string.IsNullOrEmpty(Request["Description"]) && !string.IsNullOrEmpty(Request["key"]))
{
var n = from x in DataContext.DirectoryTrees where x.ID == Convert.ToInt32(Request["key"]) select x;
foreach (var j in n)
{
j.ModifyBy ="000";
j.ModifyDate = System.DateTime.Now;
j.Remarks =string.IsNullOrEmpty(Request["Remarks"])?"":Server.UrlDecode(Convert.ToString(Request["Remarks"]));
j.Description = string.IsNullOrEmpty(Request["Description"]) ? "" : Server.UrlDecode(Convert.ToString(Request["Description"]));
}
DataContext.SubmitChanges();
}
}
1/注意红色字部份,在Javascript中使用了encodeURIComponent()进行编码转换
2/其它后台不用使用Server.UrlDecode()解码也不会乱码了
- javascript 转URL传中文参数乱码问题解决办法
- url传中文乱码问题解决办法
- url传中文参数乱码
- url传中文参数乱码解决办法
- jsp url传中文参数乱码问题
- jsp前台url传中文参数乱码
- url中传中文参数乱码问题
- URL传中文乱码
- url传中文乱码
- 在url中传中文值乱码问题解决方法
- flex URLRequest传中文参数到后台乱码问题解决方法
- flexURLRequest传中文参数到后台乱码问题解决方法
- jsp页面url参数传中文乱码问题
- JS中URL传中文参数引发的乱码问题
- JS中URL传中文参数引发的乱码问题
- struts2的s:url标签传中文参数乱码问题
- JS URL传中文参数引发的乱码问题
- JS URL传中文参数引发的乱码问题
- linux XFRM整体框架简单分析
- 【转】unix编程学习路线
- SampleGrabber开发问题与解决方案
- 关于ListView显示多种不同布局
- Sphinx
- javascript 转URL传中文参数乱码问题解决办法
- C#对Windows文件/文件夹/目录的一些操作总结
- 查找Linux 进程目录
- NGUI研究院之自制ListView动态增加与删除(三)
- 360python专栏——我们在360如何使用Python – 引言
- 杭电ACM 2002 计算球体积
- tea算法
- mysql中engine=innodb和engine=myisam的区别
- V4L2视频驱动和应用分析