Jquery obtains the values of multiple checkboxes and submits them to php asynchronously.

Source: Internet
Author: User
: This article mainly introduces jquery to obtain multiple checkbox values and submit them to php asynchronously. if you are interested in the PHP Tutorial, refer to it. Html code:

 
 
 
 
 

My data in html is read from the database and can be understood as the following code:

  • User 1
  • User 2
  • User 3
  • User 4
  • Jquery code:

    1var mt4Ids = []; 2 $ ('input [name = uid] '). each (function () {3if (this. checked) {4 mt4Ids. push ($ (this ). val (); 5} 6}); 7 data = {8 mt4Ids: JSON. stringify (mt4Ids) 9}; 10var pUrl = "/a/manageUser.html"; 11 $. post (pUrl, data, function (data) {12if (data. state = 1) {13 alert (data. msg); 14 location. href = "/h/permission.html"; 15} else {16 alert ("Operation failed"); 17} 18}, 'json ');

    PHP code

    1 $ mt4Ids =! Empty ($ _ POST ['mt4kids'])? $ _ POST ['mt4kids']: false; 2 3 $ stripMt4Ids = preg_replace ('/[\ "\ [\]/','', $ mt4Ids ); 4 $ mt4IdsToArr = explode (',', $ stripMt4Ids); 5 6 foreach ($ mt4IdsToArras $ uid) {7 permission_relation: add ($ uid, $ gid ); 8} 9 $ data = array (10 'state' => 'MSG '=> 'Operation successful '12); 13 echo json_encode ($ data); 14 returnfalse;

    // $ Gid can be ignored

    The above introduces jquery's asynchronous submission of multiple checkbox values to php, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

    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.