ajax大量刪除資料

來源:互聯網
上載者:User

標籤:mapping   new   value   row   刪除   logs   throws   代碼   confirm   

    做網頁經常要選擇大量刪除資料,基本都是非同步請求大量刪除,用到更多的是ajax大量刪除。思路是前端ajax請求,傳入ids(要刪除對象id的字串數組)到後台。

   後台再遍曆id,調用刪除介面,刪除資料。返回json給前台。

   代碼例子如下:

    

 1  function deleteSaleChance() { 2      var selectedRows = $("#dg").datagrid("getSelections"); 3      if(selectedRows.length==0){ 4          $.messager.alert("系統提示","請選擇要刪除的資料!"); 5          return; 6      } 7      var strIds=[]; 8      for(var i=0;i<selectedRows.length;i++){ 9          strIds.push(selectedRows[i].id);10      }11      var ids= strIds.join(",");12      $.messager.confirm("系統提示","您確定要刪除這<font color=red>"+selectedRows.length+"</font>條資料嗎?",function(r){13          if(r){14              $.post("${pageContext.request.contextPath}/saleChance/delete.do",{ids:ids},function(result){15                  if(result.success){16                      $.messager.alert("系統提示","資料已成功刪除!");17                      $("#dg").datagrid("reload");18                  }else{19                      $.messager.alert("系統提示","資料刪除失敗,請聯絡系統管理員!");20                  }21              },"json")22          }23      });24 }
View Code

   

 1     @RequestMapping("/delete") 2     public String delete(@RequestParam(value="ids")String ids,HttpServletResponse response) throws Exception{ 3         String[] idsStr = ids.split(","); 4         for(int i=0;i<idsStr.length;i++){ 5             saleChanceService.delete(Integer.parseInt(idsStr[i])); 6         } 7         JSONObject result = new JSONObject(); 8         result.put("success", true); 9         ResponseUtil.write(response, result);10         return null;11     }
View Code

 

ajax大量刪除資料

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.