jquery Ajax implementation of bulk deletion of specific ideas and code _ajax related

Source: Internet
Author: User
JS page jquery code
Copy Code code as follows:

JavaScript Document
$ (document). Ready (function () {
Select All
$ ("#allChk"). Click (function () {
$ ("Input[name= ' Subchk ']"). Prop ("Checked", this.checked);
});
Radio
var Subchk = $ ("Input[name= ' Subchk ']")
Subchk.click (function () {
$ ("#allChk"). Prop ("checked", subchk.length = = Subchk.filter (": Checked"). length? true:false);
});
/* Bulk Delete * *
$ ("#del_model"). Click (function () {
Determine whether to select at least one item
var checkednum = $ ("input[name= ' Subchk ']:checked"). Length;
if (Checkednum = = 0) {
Alert ("Please select at least one!") ");
Return
}
Batch Selection
if (confirm) (OK to delete the selected item?) ")) {
var checkedlist = new Array ();
$ ("Input[name= ' Subchk ']:checked"). each (function () {
Checkedlist.push ($ (this). Val ());
});
$.ajax ({
Type: "POST",
URL: "Deletemore",
Data: {' Delitems ': checkedlist.tostring ()},
Success:function (Result) {
$ ("[name = ' Subchk ']:checkbox"). attr ("checked", false);
Window.location.reload ();
}
});
}
});
});
page Elements
<a href= "#" id= "Del_model" ><span> Delete user </span>
<th class= "tal" ><input type= "checkbox" id= "Allchk"/> Full selection </th>
<td><input type= "checkbox" Name= "Subchk" value= "${user.id}"/></td>

callback function, what needs to be done after the request is completed: Here is to remove the selected checkbox (because it is used to freemarker the list cycle, remove the checkbox after the data change, there are the corresponding unknown checkbox was selected, need to remove).
Copy Code code as follows:

Success:function (Result) {
$ ("[name = ' Items ']:checkbox"). attr ("checked", false);
Window.location.reload ();
}

Java Background Code
Copy Code code as follows:

@RequestMapping (value = "/deletemore", method = Requestmethod.post)
Public String Deletemore (httpservletrequest request, httpservletresponse response) {
String items = Request.getparameter ("Delitems");
string[] Item = Items.split (",");
for (int i = 0; i < item.length; i++) {
Userservice.delete (Integer.parseint (item[i));
}
return "Redirect:list";
}

Effect Chart:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.