ashx Json数据

List<Photo> photos=new List<Photo>();
  string json = ser.Serialize(photos);
        return json;

在ajaxList.ashx中获得后台数据,以Json格式返回给前台。

//时间格式转换
  function ChangeDateFormat(cellval) {
            var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            return date.getFullYear() + "-" + month + "-" + currentDate;
        }


$.getJSON("AjaxList.ashx", function (data) { if (data.length > 0) { $.each(data, function (key, value) { //对数据的操作 //each 相当于foreach var table = $("<table id='photos' cellspacing=0></table>") var head = $("<tr><th>编号</th><th>标题</th><th>图片</th><th>点击次数</th><th>上传时间</th><th>操作</th></tr>"); table.append(head); //遍历data 数组 数据 $.each(data, function (key, value) { // this 数组中的一个元素 json var tr = $("<tr></tr>"); var td = $("<td>" + (key + 1) + "</td>"); tr.append(td); td = $("<td>" + value.PTitle + "</td>"); tr.append(td); td = $("<td><img width='150px' src='images/upload/" + value.PUrl + "'></td>"); tr.append(td); td = $("<td>" + value.PClicks + "</td>"); tr.append(td); td = $("<td>" + ChangeDateFormat(value.PTime) + "</td>"); tr.append(td); td = $("<td>删除 编辑</td>"); tr.append(td); table.append(tr); }) $("#list").append(table); }) }

 

posted @ 2013-01-15 14:44  南潇湘  阅读(730)  评论(0编辑  收藏  举报