日期:2014-05-20 浏览次数:20787 次
jQuery.noConflict(); jQuery(document).ready(function () { /* * 加载名单返回类型json—list * @param {Object} data */ var url = "aa.action"; var params; jQuery.getJSON(url,params,function callback(data){ alert("2");//返回不了 jQuery.each(data.items,function(i,item){ jQuery("#maindiv").append(item.cname); });//这句有没有问题,我参照jquery+ajax帮助文档写的 }) });
<div id="maindiv"></div>
package com.tyut.actions; import java.util.List; import net.sf.json.JSONArray; import com.opensymphony.xwork2.Action; import com.tyut.domain.Candiate; import com.tyut.service.CandiateService; public class CandiateAction { private Candiate candiate; public Candiate getCandiate() { return candiate; } private JSONArray resulttype; public JSONArray getResulttype() { return resulttype; } public void setResulttype(JSONArray resulttype) { this.resulttype = resulttype; } public void setCandiate(Candiate candiate) { this.candiate = candiate; } public String aa(){ CandiateService candiateService = new CandiateService(); List<Candiate> candiateList = candiateService.getList(); /*for (Iterator iter = candiateList.iterator(); iter.hasNext();) { Candiate candiate = (Candiate) iter.next(); System.out.println(candiate.getCname()); } */ JSONArray jsarry=new JSONArray(); jsarry=JSONArray.fromObject(candiateList); resulttype=jsarry; return Action.SUCCESS; } }
<package name="aa" namespace="/" extends="json-default"> <action name="aa" class="com.tyut.actions.CandiateAction" method="aa"> <result type="json"> <param name="root">resulttype</param> </result> </action> </package>