JQuery selects the selected values of all check boxes and submits data asynchronously using Ajax.

Source: Internet
Author: User

JQuery selects the selected values of all check boxes and submits data asynchronously using Ajax.

When I was working on a background management system project with a friend yesterday, it involved checking box batch operations. It would be convenient to submit a submit form, but it would be a bit of a hassle to Implement Asynchronous Data submission using jQuery and Ajax, because Ajax is basically not used to submit check box data in batches in my previous projects, I will share it today.

The project I am working on is complicated in some places. Here I will just give a small example to understand it.

First, I made a simple interface for multiple check boxes,

This is a simple interface for submitting multiple check boxes. The Code is as follows:

1 <body> 2 <div> 3 <input type = "checkbox" name = "check" value = "1"/> check box 1 4 <input type = "checkbox" name = ""check" value = "2"/> check box 2 5 <input type = "checkbox" name = "check" value = "3"/> check box 3 6 <br/> 7 <input type = "checkbox" name = "check" value = "4"/> check box 4 8 <input type = "checkbox" name = "check" value = "5 "/> checkbox 5 9 <input type = "checkbox" name = "check" value = "6"/> check box 610 <br/> 11 <input type = "checkbox" name =" check "value =" 7 "/> check box 712 <input type =" checkbox "name =" check "value =" 8 "/> check box 813 <input type =" checkbox "name = "check" value = "9"/> check box 914 <input type = "button" id = "dosubmit" value = "Submit"> 15 </div> 16 </body>

Then I began to write the jQuery program. The Code is as follows:

1 <script> 2 $ ('# dosubmit '). click (function () {3 var checkID ={}; // defines an empty array of 4 $ ("input [name = 'check']: checked "). each (function (I) {// store the values of all checked check boxes in the array 6 checkID [I] = $ (this ). val (); 7}); 8 9 // use Ajax to pass the parameter 10 $. post ('ajax. php ', {checkID: checkID}, function (json) {11 12}, 'json') 13}) 14 </script>

Note: before writing jQuery, you must introduce the JQ library file. Otherwise, it will be useless. Don't take it seriously. Sometimes this is what I do .......

Now, all the preparations are ready. Start the test:

I first selected several boxes:

Click "Submit" to enable F12 debugging. Result:

OK. Now you have implemented using jQuery to submit data with the Ajax batch operation check box. Here is a simple example of jQuery's combination of Ajax usage. The interface and code are simpler.

This article is original content. For the purpose of respecting others' work, please enter the address of this Article for reprinting:

Http://www.cnblogs.com/luokakale/p/7281628.html

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.