无标题页
panel content. panel content.
panel content.
前两种方法带不带
下面文件,我写在ashx中
<%@ WebHandler Language="C#" Class="Handler_login" %> using System; using System.Web; using System.Text; public class Handler_login : IHttpHandler { public string name =""; public string pwd = ""; public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain";//无格式正文 if ((context.Request["name"] != null) && (context.Request["pwd"] != null)) { this.name = context.Request["name"].ToString(); this.pwd = context.Request["pwd"].ToString(); context.Response.ContentType = "application/json;charset=utf-8"; context.Response.Write(ToJson(new string[]{"name@"+name,"pwd@"+pwd})); //可以增加一个带bool值:context.Response.Write(ToJson(new string[] { "success@" + true, "name@" + name, "pwd@" + pwd })); } } public bool IsReusable { get { return false; } } public string ToJson(string[] array) { StringBuilder s = new StringBuilder(128); s.Append("["); for (int i = 0; i < array.Length; i++) { s.Append("{"); s.Append("\""); s.Append(array[i].Split('@')[0]); s.Append("\""); s.Append(":"); s.Append("\""); s.Append(array[i].Split('@')[1]); s.Append("\""); s.Append("}"); if (i != (array.Length-1)) s.Append(","); } s.Append("]"); return s.ToString(); } }
ToJson 是为了生成Json用的,注意下,Json的格式为[{"name":"123"}.{"pwd":"123"}],这里的必须用的双引号,不然JQuery就显示一个错误,收不到服务器端传回的数据.
京公网安备 11010502049817号