日期:2014-05-16  浏览次数:20614 次

servlet与ajax之间的数据传递
List<XtwhYhwh> xtwhYhwhs =xtwhYhwhServlet.xtwhYhwhDAO.findByBz(bz);
   	  //返回json时会有问题因为hibernate的延迟加载问题
	     System.out.println(xtwhYhwhs+"14541541");
		JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.setJsonPropertyFilter(new net.sf.json.util.PropertyFilter(){
          
          public boolean apply(Object source, String name, Object value) {
              if(name.equals("rczxUnitinfo")||name.equals("xtwhYhwhs")){
                  return true;
              }else{
              return false;
              }
          }});
      
     JSONArray json=JSONArray.fromObject(xtwhYhwhs,jsonConfig);
         try {
      	response.setContentType("text/html;charset=gb2312");
          PrintWriter out=response.getWriter();
          out.println(json.toString());
          out.flush();
          out.close();
      } catch (IOException e) {
          e.printStackTrace();
      }




      function initXtwhYhwh()
  	  { 
      	   	var id = $("#bmbz").val(); 
      	    $.ajax({
  		    type: "POST",
  		    dataType:"json",
  		    url: "<%=SystemResource.DOMAIN%>/XtwhYhwhServlet",
  		     data: "id="+id,
  		    success: function(xtwhYhwhs){
  		   	  $("#xtwhyh").empty();
  			  var i =$("#xtwhyh").val();
  			  $(xtwhYhwhs).each(function(i){
  					   $("#xtwhyh").append("<option name='xtwhyh'  value=\""+xtwhYhwhs[i].userid+"\">"+xtwhYhwhs[i].username+"</option>");
  			  });
  		   }
  		});
  		  
  	  }