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 閱讀(1595) 評論(0)  編輯  收藏 所屬分類: Ajax簡單應用

          只有注冊用戶登錄后才能發表評論。


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          留言簿

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          主站蜘蛛池模板: 涟源市| 浦县| 西青区| 门头沟区| 德惠市| 高台县| 丹阳市| 丘北县| 彰武县| 连平县| 高密市| 子洲县| 武清区| 宁武县| 准格尔旗| 永寿县| 德惠市| 奉化市| 富锦市| 垦利县| 浦城县| 阿拉善右旗| 乌兰察布市| 三江| 吐鲁番市| 固原市| 新丰县| 杭锦旗| 河池市| 太湖县| 阿坝县| 河东区| 政和县| 雷山县| 晋中市| 淮南市| 仪陇县| 宁蒗| 大同市| 明溪县| 赤壁市|