ajax數據提交 遍歷顯示例子

<td><div class="button"><div class="buttonContent"><button class="saveAssPersonnelUser">保存聯繫人</button></div></div></td> 

 

//常用聯繫人添加
    $(".saveAssPersonnelUser").click(function(){
     var org3_ids=$("#org3_ids").val();
     var user_id=$("#user_id").val();
     jQuery.ajax({
            type: 'POST',
            dataType:'json', //設置爲json 類型後返回數據不需要 再次轉換;
            contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
            url: '${contextPath}/wzoa/associatedpersonnel/save?org3_ids='+org3_ids+'&user_id='+user_id,
            error: function() {
              alertMsg.error('聯繫人添加失敗!');
            },
            success: function(data) {
            $("#tbody_index_html").html("");
            var tbody_index_html="";
            for(var p in data){  //for循環直接遍歷數據
             tbody_index_html+="<tr id='personRoleRow_"+data[p].id+"'>";
    tbody_index_html+="<td>"+(parseInt(p)+1)+"</td>";
    tbody_index_html+="<td>"+data[p].recipient_name+"</td>";
    tbody_index_html+="<td>"+data[p].organization_name+"</td>";
    tbody_index_html+="<td>"+data[p].recipient_dept_name+"</td>";
    tbody_index_html+="<td>"+data[p].post+"</td>";
    tbody_index_html+="<td>"+data[p].posttype+"</td>";
    tbody_index_html+="<td>"+data[p].direct_leadership=='00'?'否':'是'+"</td>";
    tbody_index_html+="<td>";
    tbody_index_html+="<div class='button'><div class='buttonContent'><button id='submit_"+data[p].id+"' class='assPersonnelUser'>移除</button></div></div>";
    tbody_index_html+="<div class='button' style='margin-left: 10px;'><div class='buttonContent'><button id='update_"+data[p].id+"' class='updateAssPersonnelUser'>設置/取消(直接領導)</button></div></div>";
    tbody_index_html+="</td>";
    tbody_index_html+="</tr>";
            } 
            $("#tbody_index_html").html(tbody_index_html);
      }  
        }); 
    });

 

 

 

@RequiresPermissions("AssociatedPersonnel:save")
 @RequestMapping(value = "/save")
 public @ResponseBody
 Object save(HttpServletRequest request, @RequestParam(value = "org3_ids") String org3_ids,
   @RequestParam(value = "user_id") int user_id) {
  try{//保存基本信息附件信息
   associatedPersonnelService.save(request,user_id,org3_ids);
   //關聯人員列表
   Map<String, Object> condition = new HashMap<String, Object>();
   condition.put("personnel_id", user_id);
   List<Map<String, Object>> personnelList = associatedPersonnelService.getAssociatedPersonnelList(condition);
   return JSON.toJSON(personnelList); //返回json格式數據
  }catch(Exception e){
   log.error("{}", e);
   return AjaxObject.newError("保存信息失敗!").toString();
  }
 }  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章