ajax在火狐中传中文出现乱码的解决方法
function checkSJtitle() { var title = $.trim($("#ctl00_ctRight_txtTitle").val()); if (title == "" || title == null) { return false; } if (title.length >= 5 && title.length <= 15) { title = escape(title); $.ajax({ type: "post", dataType: "html", url: "CheckSJTitle.ashx?title=" + title + "", data: "", success: function (data) { if (data == "succee") { $("#spanTS").hide(); return true; } else { $("#spanTS").show(); return false; } } } ) } }
public void ProcessRequest(HttpContext context) { context.Response.Write(checkSJ(HttpUtility.UrlDecode(context.Request.QueryString["title"].ToString()))); }
首先是在jquery里先对传值escape下,然后在CheckSJTitle.ashx页面中HttpUtility.UrlDecode得到。