posts - 0,  comments - 19,  trackbacks - 0
今天使用$.getJSON(url,null,function call(data){});获取数据:

  前台js代码:
<script type="text/javascript">
//<![CDATA[ 
function convertUrl(url){
    var timestamp 
= (new Date()).valueOf();
    
if(url.indexOf("?")>=0){
        url 
= url+"&t="+timestamp;
    }
else{
        url 
= url+"?t="+timestamp;
    }
    
return url;
}

$(function(){
    var newUrl01 
= "/html/school/schoolTJSchoolWeb.do?sch_hot=3";
    $.getJSON(convertUrl(newUrl01),
null,function call(data){  
        var myTitle
="";
        
for(var i=0; i<$(data).length-1 ;i++){
            var otherObj 
= $(data).get(i+1);
            
if(otherObj.sch_name.length>21){
            myTitle 
+="<li id='sch_name'><a href='/html/school/viewInfoSchoolWeb.do?sch_id="+otherObj.sch_id+"'>"+otherObj.sch_name.substring(0,21)+'..'+"</a></li>";
            }
else{
            myTitle 
+="<li id='sch_name'><a href='/html/school/viewInfoSchoolWeb.do?sch_id="+otherObj.sch_id+"'>"+otherObj.sch_name+"</a></li>";
            }
        }
        $(
"#school_ul01").html(myTitle);
    }); 
    
    var newUrl 
= "/html/school/adSchoolWeb.do";
    $.getJSON(convertUrl(newUrl),
null,function call(data){  
        var myTitle
="";
        
for(var i=0; i<$(data).length ;i++){
            var otherObj 
= $(data).get(i);
            myTitle 
+="<li><a href='#'><img width='220' height='70' src='/"+otherObj.AD_FILE_PATH+"' alt='广告' /></a></li>";
        }
        $(
"#ad_ul").html(myTitle);
    }); 
});
         
//]]>
</script>

  前台jsp代码:

<html>
<head>
<title></title>
</head>
<body>
<div>
  
<ul id="school_ul01">
    
<li></li>
  
</ul>
  
<ul id="ad_ul">
    
<li></li>
  
</ul>
</div>
</body>
</html>

  后台java代码:

    
public void  schoolTJ() throws Exception{
        HttpServletResponse response 
= ServletActionContext.getResponse();
        HttpServletRequest request 
= ServletActionContext.getRequest();
        String sch_hot 
= request.getParameter("sch_hot");
        List
<DragonSchool> schoolList = (List<DragonSchool>this.webDragonSchoolService.list("select * from dragon_school where SCH_HOT ='"+sch_hot+"' limit 0,10", DragonSchool.class); 
        Gson gson 
= new Gson();
        String schoolListToJson 
= gson.toJson(schoolList);
        response.setCharacterEncoding(
"utf-8");
        response.getWriter().write(schoolListToJson);
        response.getWriter().close();
    }
    
    
public void ad() throws Exception{
        HttpServletResponse response 
= ServletActionContext.getResponse();
        List adList 
= webDragonAdvertisingService.webList(pager, "4"null9);
        Gson gson 
= new Gson();
        String adListToJson 
= gson.toJson(adList);
        response.setCharacterEncoding(
"utf-8");
        response.getWriter().write(adListToJson);
        response.getWriter().close();
    }
posted on 2012-03-26 10:47 canry Tong 阅读(1585) 评论(0)  编辑  收藏 所属分类: Ajax简单应用

只有注册用户登录后才能发表评论。


网站导航:
 
<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

留言簿

文章分类

文章档案

搜索

  •  

最新评论