ASHX内容:
#region IHttpHandler Members
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/x-javascript";
List<User> list = new List<User>();
for (int i = 0; i < 10; i++)
{
list.Add(new User { UserName = "zzl" + i, Tel = "13521972991" });
}
string str = "[";
list.ForEach(i =>
{
str += "{" + string.Format("\"UserName\":\"{0}\", \"Telephone\":\"{1}\"", i.UserName, i.Tel) + "},";
});
str = str.TrimEnd(',') + "]";
context.Response.Write(str);
}
#endregion
ASPX内容:
function bindDatajQueryAjaxJson() {
$.ajax({
url: "Handler2.ashx",
dataType: "json",
cache: false,
data: null,
type: "GET",
success: function (data) {
var msg = "";
for (var i = 0, length = data.length; i < length; i++) {
msg += "<Div style='color:red'>UserName:" + data[i].UserName + ",Telephone:" + data[i].Telephone + "</div>";
}
$("#msg2").html(msg);
}
});
}
bindDatajQueryAjaxJson();
作者:仓储大叔,张占岭,
荣誉:微软MVP
标签:UserName,data,list,Telephone,JSON,ashx,str,msg,aspx From: https://blog.51cto.com/u_15765017/5945630