`

jquery 异步调用业务层的方法,然后返回一个list。在jsp页面上填充

 
阅读更多

在后台返回json格式的数据,然后用jquery读取分析。

后台

Java code
JSONObject json = new JSONObject(); List < Map > maps = new ArrayList < Map > (); List < Notice > notices = this .getNoticeService().findAll( this .getPageNo(), this .getPageSize()).getDatas(); SimpleDateFormat sdf = new SimpleDateFormat( " yyyyMMdd HH:mm:ss " ); for (Notice notice : notices) { Map < String, Object > property = new HashMap < String, Object > (); property.put( " noticeId " , notice.getNoticeId()); property.put( " title " , notice.getTitle()); property.put( " addTime " , sdf.format(notice.getAddTime())); maps.add(property); } json.put( " rows " , maps); this .renderText(json.toString());


前台

JScript code
function PageClick(pageclickednumber){ var pageSize = 10 ; $.ajax({ type: " get " , dataType : ' json ' , url: " notice!list.action " , data: ({ pageNo : pageclickednumber, pageSize : pageSize }), beforeSend: function () { $( " #all " ).mask( " 加载中... " ); }, success: function (data) { $( " #all " ).unmask(); if (data != 0 ) { analyJson(data); $( " #pager " ).pager({ pagenumber: pageclickednumber, pagecount: pageCount, buttonClickCallback: PageClick}); } else { alert( " 没有权限! " ); } } }); } function analyJson(data) { var json = eval(data.rows); var len = json.length; if (len > 0 ) { $( " #noticeList " ).html( '' ); for ( var i = 0 ; i < len; i ++ ) { var append = " <li id='li " + json[i].noticeId + " '>[ " + json[i].addTime + " ]<br/><a href='#'> " + json[i].title + " </a></li> " $( " #noticeList " ).append(append); } } }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics