Ajax练习:获取指定管理员信息
1.读取数据的一般处理程序页面GetAdmin.ashx
List<Admin> admins = AdminManager.getAdminall(); StringBuilder sb = new StringBuilder(); foreach (Admin ad in admins) { sb.Append(ad.Id).Append("|").Append(ad.Name).Append("$"); } context.Response.Write(sb.ToString());
2.页面中javascript代码
$.post("GetAdmin.ashx", function (data, status) { if (status != "success") { $("#ulcom").append("<li>加载失败</li>"); return; } var lines = data.split("$"); for (var i = 0; i < lines.length; i++) { var line = lines[i]; var fields = line.split("|"); var com = $("<li>ID:" + fields[0] + "Name:" + fields[1] + "</li>"); $("#ulcom").append(com); } });