下面是我的程序
HTML :
无标题页
request.ashx :
Code
using System;
using System.Web;
public class request : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string tab ="来自服务器的信息:您好 " context.Request.QueryString["val"].ToString() " --by time:" DateTime.Now.ToLongTimeString();
context.Response.Write(tab);
}
public bool IsReusable {
get {
return false;
}
}
} baidu搜了一大堆 大致意思是 AJAX提交数据时,使用的是UTF-8的编码 并且不可以设置为其他格式
如何解决呢 最后发现一个JS的函数escape与unescape 用escape()对将要提交的汉字进行编码,会出现大致 的字符,类似与.NET中Server.UrlEncode()与Server.UrlDecode();
将JS获得的表单值进行重新编码
Code
var txtval=escape(document.getElementById("txt").value);OK, 问题解决! 其他可能还有别的办法至今没遇到 希望这个办法能帮到遇到这种困境的朋友