ajax get post 中文乱码解决办法

2018-09-05 23:39

阅读:836

  前台:

   var username = $("#UserName").val(); var tel = $("#tel").val(); var yzm = $("#yzm").val(); var con = $("#con").val(); layer.msg('正在提交数据', { icon: 16 }); var data = { "username": escape(username), "tel": escape(tel), "yzm": yzm ,"con":escape(con),"jxid":<%=Request["uid"].ToString() %>}; $.post('ajaxpost.ashx?type=ask', data, function (rdata) { if (rdata == "ok") { layer.alert("提交成功,我们会尽快回复,请随时关注网站", { skin: 'layui-layer-molv', icon: 5 },function(index) { location.href="jiaxiao<%=Request["uid"].ToString() %>.aspx?x="+Math.random()+"#askhead"; }); } else { layer.alert(rdata, { skin: 'layui-layer-molv', icon: 5 }); return; } });

  后台========================

   string con = code.NoHTML(HttpUtility.UrlDecode( context.Request["con"].ToString())); int jxid = int.Parse(context.Request["jxid"].ToString()); string tel=code.NoHTML(HttpUtility.UrlDecode(context.Request["tel"].ToString())); string username=code.NoHTML(HttpUtility.UrlDecode(context.Request["username"].ToString())); string yzm = HttpContext.Current.Request["yzm"].ToString();

  总结:前台用js 的escape 方法编码 后台HttpUtility.UrlDecode解码就可以了!


评论


亲,登录后才可以留言!