$.getJSON("Photolist.ashx",function (msg){
//每次加载之前清空
$("#content").html("");
//动态创建table
var table=$("<table id='pList'></table>");
//添加表头
table.append($("<tr><th>序号</th><th>名字</th><th>照片</th><th>点击次数</th><th>支持</th><th>反对</th><th>时间</th><th>操作</th></tr>"));
for(var i=0;i<msg.length;i++){
var photo=msg[i];
var tr=$("<tr ></tr>");
var td=$("<td>"+(i+1)+"</td>");
tr.append(td);
var time=new Date().getTime();
td=$("<td><a href='DetailPhoto.aspx?).append(table);
});
cs:
public class Photolist : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write(GetTable());
}
protected string GetTable()
{
MyPhotoList.BLL.Photos bll = new MyPhotoList.BLL.Photos();
List<MyPhotoList.Model.Photos> list = bll.GetModelList("");
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(list);
}
使用之前必须添加命名空间using System.Web.Script.Serialization;