如何學好java

          如何學好java,其實很簡單,只要用心體會,慢慢積累!
          posts - 106, comments - 7, trackbacks - 0, articles - 3
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          ajax json級聯

          Posted on 2011-12-21 15:49 哈希 閱讀(290) 評論(0)  編輯  收藏 所屬分類: Js and Jquery 常用總結
          <%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>


           $(function(){$("#sendAddress").change(function(){
           
              var sendAddress=$("#sendAddress").val();
              getCustomerInfo(sendAddress);
              });
            });
            //出貨方信息填充
            function getCustomerInfo(id){
                 //alert(id);
                  $.ajax({
                       type: 'get',
                       url: "
          <c:url value='/k4_oldGoldStorsge/getCustomerInfoByAddressId/'/>"+id,
                       dataType: 'json',
                       success: function(data) {
                          alert(data.name);
                          $("#supplyer").val(data.linkman);   
                          $("#supplyIdentityCard").val(data.identification);        
                          $("#supplyerMobile").val(data.mobile);     
                          $("#supplyerPhone").val(data.tel); 
                          //$("#").val(data.);                        
                      }
                  });
              }
              
              
              
              $(function(){$("#outStorageList").change(function(){
           
              var outStorageList=$("#outStorageList").val();
              //alert(outStorageList);
              //getCustomerInfo(sendAddress);
               getAddressList(outStorageList)
              });
            });
              
              
              
              
              function getAddressList(id){
                 //alert(id);
                  $.ajax({
                       type: 'get',
                       url: "
          <c:url value='/k4_oldGoldStorsge/getAddressByCustomerId/'/>"+id,
                       dataType: 'html',
                       success: function(data) {
                        var address=eval(data);
                       //遍歷取值             
                        $.each(address,function(i,n){
                           $("#getAddress").append($("
          <option value='"+address[i].id+"'></option>").text(address[i].address));  
                        });
                      }
                  });
              }
              
              
              
               $(function(){$("#getAddress").change(function(){
                   var sendAddress=$("#getAddress").val();
                   getMenInfo(sendAddress);
                 });
               });
              
              
              
              function getMenInfo(id){
                  $.ajax({
                       type: 'get',
                       url: "
          <c:url value='/k4_oldGoldStorsge/getCustomerInfoByAddressId/'/>"+id,
                       dataType: 'json',
                       success: function(data) {
                          $("#receiver").val(data.linkman);   
                          $("#receiverIdentityCard").val(data.identification);        
                          $("#receiverMobile").val(data.mobile);     
                          $("#receiverPhone").val(data.tel); 
                          //$("#").val(d
          /**
               * 收貨方ID獲取地址信息
               * 
          @return
               
          */

              
          public void getAddressByCustomerId(String id) {
                  List
          <Address> list=new ArrayList<Address>();
                  list
          =oldGoldStorageService.findAddressList(id);
                  StringBuilder json 
          = new StringBuilder();
                  json.append(
          "[");
                  
          for (int i = 0; i < list.size()-1; i++{
                      json.append(
          "{'id':'").append(list.get(i).getId()).append("',");
                      json.append(
          "'address':'").append(list.get(i).getAddressDeatil()).append("'},");
                  }

                  json.append(
          "{'id':'").append(list.get(list.size()-1).getId()).append("',");
                  json.append(
          "'address':'").append(list.get(list.size()-1).getAddressDeatil()).append("'}");
                  json.append(
          "]");    
                  System.out.println(json);
                  
          this.renderJSON(json.toString());
              }
          ata.);                        
                      }
                  });
              }
              
              
              
              
              


          1. <script type="text/javascript">   
          2. $(document).ready(function(){   
          3.  var url='TypeGet?d='+Math.random();/*使用隨機數解決jquery的緩存問題*/  
          4.  $.get(url,   
          5.    function dedit(data){   
          6.     var m=eval(data);   
          7.         $.each(m, function(i) {   
          8.            //alert(s[i]);   
          9.            $('#pselect').append('<option value="'+m[i].no+'">' + m[i].name+ '</option>');   
          10.   
          11.      });   
          12.   
          13. });    
          14. </script>  

          1. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {   
          2.   // TODO Auto-generated method stub   
          3.   request.setCharacterEncoding("UTF-8");/*解決中文亂碼的問題*/  
          4.    response.setCharacterEncoding("UTF-8");   
          5.       
          6.   ArrayList result=new ArrayList();   
          7.   Connection conn=null;   
          8.   Statement st=null;   
          9.   ResultSet rs=null;   
          10.      
          11.   try{   
          12.       
          13.    conn=DBConnection.getConnection();    
          14.    st=conn.createStatement();   
          15.    rs=st.executeQuery("select * from ddpms_devicetype order by name");   
          16.    while(rs.next()){   
          17.     DevicetypeBean dt=new DevicetypeBean();   
          18.     dt.setNo(rs.getInt("no"));   
          19.     dt.setName(rs.getString("name"));   
          20.     result.add(dt);   
          21.    }   
          22.   }catch(Exception e){   
          23.    e.printStackTrace();   
          24.   }   
          25.   finally{   
          26.    try{   
          27.     rs.close();   
          28.     st.close();   
          29.     conn.close();   
          30.    }catch(Exception e){   
          31.     e.printStackTrace();   
          32.    }   
          33.   }   
          34.    response.setContentType("text/html");   
          35.    PrintWriter out= response.getWriter();     
          36.   
          37.    out.write(toString(result));   
          38.  }   
          39.  public String toString(ArrayList s)      
          40.     {      
          41.         String str="[";   
          42.         for(int i=0;i<s.size();i++){   
          43.          DevicetypeBean dt=(DevicetypeBean)s.get(i);   
          44.          str+="{'no':'"+dt.getNo()+"','name':'"+dt.getName()+"'},";   
          45.         }   
          46.         str=str.substring(0,str.length()-1)+"]";    
          47.   return str;     
          48.     }  
          $(function(){$("#logisticsDistributionBook").click(function()
                  {
                var checkValues=getCoulmnValue(oTable, 'id');
               // alert(checkValues);
                var aoData = new Array();
                aoData.push( { "name": "ids", "value":checkValues } );
                if(isEmpty(checkValues)){
                     showInfo("請選擇需要處理的數據行!");
             return false;
                  }else if(!isEmpty(checkValues)){
                   $.ajax({
                    type: 'post',
                    url: "<c:url value='/k4_oldGoldStorsge/checkDispatchStatusId/make/1'/>",
                    dataType: 'json',
                    data: aoData,
                    success: function(data) {
                    //alert(data);
                    if(parseInt(data)>=1){
                       //alert(data);
                       showInfo("必須全部選擇沒有生成過物流配送書的數據!");
                       return;      
                       }else if (checkProductId()) {
                      getHidVal(checkValues);   
                      }                 
                      }
                       });
                  }
                 });
              });

          public void checkDispatchStatusId(String type, String id) {
            String myid = request().getParameter("ids");
            String[] ids = myid.split(",");
            int count = 0;
            if ("make".equals(type)) {
             count = oldGoldStorageService.findNumofDispatch(myid);
            }
            this.printHtml(count);
           }

          這兩篇也不錯!
          http://tochal.iteye.com/blog/722265

          http://blog.csdn.net/huhai463127310/archive/2009/11/29/4901654.aspx

          主站蜘蛛池模板: 深州市| 纳雍县| 苗栗县| 专栏| 娱乐| 弥渡县| 卫辉市| 高平市| 广宁县| 威信县| 肃南| 离岛区| 青神县| 通山县| 金华市| 什邡市| 德钦县| 张家川| 格尔木市| 巨野县| 上犹县| 姜堰市| 长宁区| 乐东| 随州市| 兴安盟| 新晃| 汨罗市| 贵德县| 南丰县| 泸定县| 洛南县| 五台县| 孝昌县| 阳山县| 保山市| 越西县| 剑川县| 南丹县| 九寨沟县| 冕宁县|