Home > Web Front-end > JS Tutorial > body text

jQuery getJSON code for processing json data_jquery

WBOY
Release: 2016-05-16 18:22:33
Original
1202 people have browsed it

Html code:

Copy code The code is as follows:









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");
},
Copy code The code is as follows:

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);
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!