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); }) }
  • 相关阅读:
    模拟ajax请求爬取微博
    使用nohup+& 踩到的坑
    Python3爬虫一之(urllib库)
    在linux下安装并运行scrapyd
    创建Django项目并将其部署在腾讯云上
    python解析库之 XPath
    python3中urllib库的request模块详解
    HTTP协议详解
    线程之红绿灯
    win7 64 下安装MyGeneration 遇到的问题解决方法
  • 原文地址:https://www.cnblogs.com/nanxiaoxiang/p/2861163.html
Copyright © 2011-2022 走看看