Html code:
Ashx Handler: If you need to return an object in json format, you need to set the mime type to: "application/json".
Looking at the jQuery source file, you can see that getJSON is implemented like this:
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);
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn