如何学好java

如何学好java,其实很简单,只要用心体会,慢慢积累!
posts - 106, comments - 7, trackbacks - 0, articles - 3
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ajax json级联

Posted on 2011-12-21 15:49 哈希 阅读(287) 评论(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


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


网站导航: