zoukankan      html  css  js  c++  java
  • 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); }) }
  • 相关阅读:
    字符串练习
    python基础
    熟悉常用的Linux操作
    大数据概述
    递归下降分析程序
    自动机
    词法语法分析1
    关于我对编译原理的理解
    6小时学会TypeScript入门实战教程(大地)
    kotlin
  • 原文地址:https://www.cnblogs.com/nanxiaoxiang/p/2861163.html
Copyright © 2011-2022 走看看