ajax实例

来源:互联网 发布:js实现鼠标拖动div 编辑:程序博客网 时间:2024/05/17 09:41

@RequestMapping(params = "action=getContractTypes")
    public @ResponseBody
    String getContractTypes(HttpServletRequest request, HttpServletResponse response, DraftForm form) {
        List<ConfigObject> res = UniflowConfigUtil.getObjectsByName(UniConfigEnum.CONTRACT_TYPE.getName());
        return res.toString();
//        ConfigObject result = null;
//        for(ConfigObject cof : res){
//            if(cof.getString("name").equals(request.getParameter("contractTypeName"))){
//                result = cof;break;
//            }
//
//        }
//        return result==null?"":result.toString();
    }

 

 

 

var url = "main/approve/Draft.do?action=getContractTypes";
              var subTypeKey = $("#subTypeKey").val()
              //alert(url);alert(subTypeKey);alert(dataStr);
              $.ajax({
                         type: "POST",
                         url: url,
                         data: dataStr,
                         success: function(msg){
                         var types=eval(msg);
                             $.each(types,function(index1,a){
                              if(a){
                                  $.each(a.sub,function(index2,b){
                                      if(b.key==subTypeKey){
                                        if(b.products!=undefined){
                                          $table.data("products",b.products);
                                          $tr = $("#"+protoId+"ValueTdTmpl").tmpl(data,{valueId:"",contracts:getContracts(),showDelete:true,rowNum:rowNum,products:b.products});
                                          $table.append($tr);
                                         }else{
                                             hasProducts = false;
                                         }
                                       }
                                   });
                               }
                          });
                          if(!hasProducts){
                              $table.append("<tr><td colspan='5' style='color:red;text-align:center'>你所选择的业务类型: <b>["+typeName+"]</b> 无需添加标的名称</td></tr>");
                          }
                         }

              });