首页  >  文章  >  web前端  >  jQuery getJSON 处理json数据的代码_jquery

jQuery getJSON 处理json数据的代码_jquery

WBOY
WBOY原创
2016-05-16 18:22:331188浏览

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);
}
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn