作者:马岱五号_668 | 来源:互联网 | 2018-06-16 13:08
Html代码:
代码如下:
Ashx处理程序:如果需要返回json格式的对象,需要把mime类型设置为:"application/json"。
查看jQuery源文件,可以看出getJSON这样实现的:
getJSON: function( url, data, callback ) {
return jQuery.get(url, data, callback, "json");
},
代码如下:
public void ProcessRequest(HttpContext context)
{
if (context.Request.Params["type"].Equals("ajax"))
{
context.Response.COntentType= "text/plain";
}
else
{
context.Response.COntentType= "application/json";
}
GetInfo(context);
}
public bool IsReusable
{
get
{
return false;
}
}
public void GetInfo(HttpContext context)
{
System.Collections.Generic.List listUser = UserInfoManage.GetUserInfoBySQL("Select Top 5 * From Userinfo");
IsoDateTimeConverter timeCOnverter= new IsoDateTimeConverter();
timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";
string ResJsOnStr= JsonConvert.SerializeObject(listUser, timeConverter);
context.Response.Write(ResJsonStr);
}