: 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 1User 2User 3User 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.