日期:2014-05-16  浏览次数:20345 次

ajax对action json串操作(可操作大量数据,常用于页面数据加载,如分页)
1:js

   <script type="text/javascript">
  $(document).ready(function(){
fn_Jump(1);
});

function fn_Jump(gotoPage)
{
jQuery.ajaxSetup ({cache:false});
var first = "2012-1-1";
var last = "2013-12-31";
$.getJSON("testJsonAction!openByEmpId2.action",{first:first,last:last,currPage:gotoPage},function(json){
if(json.msg!="none"){
var dataString = "";
dataString +="<TR>";
var data = json.annList;
for (index in data) {
var obj = data[index];
dataString +=" <TD>"+obj.fsContent+"</TD>";
}
dataString += "</TR>";
$("#dataList").append(dataString);
}
});




  </script>


2: struts.xml文件中的配置

   <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="ann2" extends="json-default">
<action name="testJsonAction" class="com.asia.home.cn.web.oa.TestJsonAction">
<result type="json"/>
</action>
</package>
</struts>


3:action

  private IRepAnnounceService announceService;
private List<RepAnnounce> annList;
private String msg;

// 按发布者查询公告
public String openByEmpId2() {
try {
String readType = request.getParameter("readType");
String fsEmpId = "93b7f205-0134-1000-e000-35630a0000fa";
String author = UrlUtils.decode(request.getParameter("author"),
"utf-8");
String last = request.getParameter("last");
String first = request.getParameter("first");
this.annList = announceService.findAnn(fsEmpId, new Page(), readType,
author, last, first);
} catch (Exception e) {
logger.info(e);
}
return SUCCESS;
}


public void setAnnounceService(IRepAnnounceService announceService) {
this.announceService = announceService;
}