ajax添加操作

<script>
   //显示添加分类块
   function showAddDailyType(){
    document.getElementById("divDddDailyType").style.display="";
    //document.getElementById("more").style.display="block";
   }
    //ajax 进行添加操作


   function  addDailyType(){
   var dailyTypeName = document.getElementById("dailyTypeName").value;
   $.getJSON("${pageContext.request.contextPath}/cultivatespace/dailyManager.do?method=addDailyType&dailyTypeName="+dailyTypeName+"&userId=${userId}&dailyTypeListID=${dailyTypeListID}&dailyListSort=${dailyListSort}", function(json){
     var cnt=json.length;
     var html="";
     
     var  dailyTypeId =  json.dailyTypeId;
     var dailyTypeName =  json.dailyTypeName;
     //js添加select选项
    
 document.getElementById("selectDailyType").options.add(new Option(dailyTypeName ,dailyTypeId ));

     
    });
    
    document.getElementById("divDddDailyType").style.display="none";
    var dailyTypeName = document.getElementById("dailyTypeName").value="";
   }
  
  </script>

 

<!-- 日志类型 -->
       <select>
        <c:forEach var="dailyType" items="${dailyTypeList}"
         varStatus="row">
         
         <c:if test="${(!empty dailyDto.dailyTypeId) && (dailyDto.dailyTypeId ==dailyType.dailyTypeId)} ">
          <option value="${dailyType.dailyTypeId}" selected="selected">
          ${dailyType.dailyTypeName}
          </option>
         </c:if>
         <c:if test="${empty dailyDto.dailyTypeId}">
          <option value="${dailyType.dailyTypeId}" >
          ${dailyType.dailyTypeName}
          </option>
         </c:if>
        </c:forEach>
       </select>

 

       <input value="添加分类" />
       <div style="display: none;">
        分类名称:
        <input />
        <input value="确定" />
        <input value="取消" />
       </div>

 

 

java类

public ActionForward addDailyType(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws SaveException, QueryException, IOException {
  String userId = request.getParameter("userId");
  // System.out.println(userId);
  String dailyTypeName = request.getParameter("dailyTypeName");
  
  TKgGrDailyType dailyType = new TKgGrDailyType();
  dailyType.setDailyTypeCreatetime(CommonUtil.formatDate(new Date()));
  dailyType.setDailyTypeName(dailyTypeName);
  dailyType.setDailyUserId(userId);
  dailyManagerBo.addDailyType(dailyType);
   
  
  String json = JsonUtil.bean2json(dailyType);
  PrintWriter out = response.getWriter();
  out.write(json);
  out.flush();
  return null;
  
 }

 

 

//JsonUtil类

 public static String bean2json(Object bean) {
  StringBuilder json = new StringBuilder();
  json.append("{");
  PropertyDescriptor[] props = null;
  try {
   props = Introspector.getBeanInfo(bean.getClass(), Object.class)
     .getPropertyDescriptors();
  } catch (IntrospectionException e) {
  }
  if (props != null) {
   for (int i = 0; i < props.length; i++) {
    try {
     String name = object2json(props[i].getName());
     String value = object2json(props[i].getReadMethod().invoke(
       bean));
     json.append(name);
     json.append(":");
     json.append(value);
     json.append(",");
    } catch (Exception e) {
    }
   }
   json.setCharAt(json.length() - 1, '}');
  } else {
   json.append("}");
  }
  return json.toString();
 }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值