jquery+struts2异步调用

Posted on 2013-04-23 15:31  IT_louis  阅读(176)  评论(0编辑  收藏  举报
function onchangeShow(pid){ 
 $.ajax({  
        cache:false,  
        url:'<%=path %>/aticle_ajax/twoclass.action',  
        type:'post',  
        dataType:'json',  
        data:{pid:pid},  
        success:update_c  
    });  
}
function update_c(json){
  var sort=json.sort; 
    var s_root=document.getElementById('bannerid');  
   s_root.options.length=0;  
    for(var i in sort){  
        var option = document.createElement("option");  
        var value=sort[i].claid;     
        var text=sort[i].claName;  
    
            option.text=text;  
            option.value=value;  
            s_root.options[s_root.options.length] =option;  
    }  
}
//配置文件
     <package name="aticle_ajax" extends="json-default" >
        <action name="twoclass" class="com.custom.upload.action.TwoClassAction" method="findSort">
            <result type="json"></result>
        </action>
    </package>


//java代码
//action
public class TwoClassAction extends ActionSupport {
    private transient String pid;  
     private ClassesService classeService;
     private List<Classes> lastList;//展示的list
    private Set sort;  
    public String findSort(){
        try {
            this.lastList=classeService.queryProClass(pid);
        } catch (Exception e) {
            
            e.printStackTrace();
        }
        //Banner banner=bannerService.findBanner(pid);
        sort=new HashSet();
//        if(banner!=null){
//            if(banner.getBanners()!=null&&banner.getBanners().size()!=0){
//                Set s=banner.getBanners();
//                Iterator it=s.iterator();
//                while(it.hasNext()){
//                    Banner c=(Banner)it.next();
//                    SortBean sb=new SortBean();
//                    sb.setId(c.getId());
//                    sb.setName(c.getName());
//                    sort.add(sb);
//                }
//            }
//        }
        for(Classes classes:lastList){
            sort.add(classes);
        }
        return "success";
    }
    public String getPid() {
        return pid;
    }
    public void setPid(String pid) {
        this.pid = pid;
    }
    public List<Classes> getLastList() {
        return lastList;
    }
    public void setLastList(List<Classes> lastList) {
        this.lastList = lastList;
    }
    public Set getSort() {
        return sort;
    }
    public void setSort(Set sort) {
        this.sort = sort;
    }
    public void setClasseService(ClassesService classeService) {
        this.classeService = classeService;
    }
}

 

Copyright © 2024 IT_louis
Powered by .NET 9.0 on Kubernetes