zoukankan      html  css  js  c++  java
  • 主页各块显示ajax取来的数据

    有时候需要把一些重要的信息模块显示在主页,可以用ajax实现,

    思路:发送ajax请求,在服务器取数据封装成json格式,ajax回调函数取出数据,拼表格显示

    1,封装

    
    

    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;


    public
    void getNetEventList() throws Exception{ JSONArray jsonArray = new JSONArray(); hql.append(" and clrid like '%"+getCurrentSystemUser().getId()+"%' and rwzt<>'1'"); page=jobsService.getPage(page, model, hql); for(TZdJobs job:page.getResult()){ JSONObject jsonObject = new JSONObject(); jsonObject.put("bh",job.getRwbh()); jsonObject.put("clsx", job.getClsx()); if(job.getBt().length()>10){ jsonObject.put("bt", job.getBt().substring(0,10)+"...."); }else{ jsonObject.put("bt", job.getBt()); } jsonArray.add(jsonObject); } this.renderText(jsonArray.toString()); }
    [{"bh":22,"clsx":33},{...}]

    2,回调函数中取

    /**
         * 待处理任务
         */
        $(function() {
            var url = path+"/theme/theme.action?id=001001000040003";
            var data = [];
            $.ajax({        
                async : true,            
                cache : false,
                dataType: "json",
                type : 'post',            
                url : path+'/jobs/jobs!getNetEventList.action?'+new Date(),            
                success : function(json) {
                    data = json;     
                    var $netEventList = $("#getNetEventList");
                    $netEventList.html("");
                    var table ="";
                    table +=( "<table class="table table-hover table-condensed " >");
                    table+="<thead><tr><th>任务编号</th><th>任务标题</th><th>处理时限</th></tr>";
                    table+="<tbody>";
                    for(var i=0;i<data.length;i++){
                        table +=("<tr><td><a href=""+url+"" >"+data[i].bh+"</a></td><td>"+data[i].bt+"</td><td>"+data[i].clsx+"</td></tr>");
                    }
                    table +=("</tbody>");
                    table +=("</table>");
                    $netEventList.append(table);
                }        
            });
        });

    444

    有问题在公众号【清汤袭人】找我,时常冒出各种傻问题,然一通百通,其乐无穷,一起探讨


  • 相关阅读:
    HTML
    数据库
    EF增删查改(三)------终极版
    三层的之间的引用
    sql:PostgreSQL
    csharp:SQLite and Access using C# code read data
    sql:Mysql create view,function,procedure
    sql: MySQL and Microsoft SQL Server Stored Procedures IN, OUT using csharp code
    Working C# code for MySql5.5 Stored Procedures IN parameters
    csharp:search and Compare string
  • 原文地址:https://www.cnblogs.com/qingmaple/p/4065187.html
Copyright © 2011-2022 走看看