The example in this article describes how jquery gets the value of multiple checkbox asynchronously submitted to PHP. Share to everyone for your reference. The implementation methods are as follows:
HTML code:
?
1 2 3 4 5 6 7 8 |
<tr> <td><input type= "checkbox" Name= "UID" value= "<?= $item [' mtaccount_id ']?> ' ></td> <td><?= $item [' mtaccount_id ']?></td> <td><?= $item [' account_id ']?></td> <td ><?= $item [' account_name ']?></td> <td><?= $item [' Server ']?></td> <td><?= $item [' Platform ']?></td> </tr> |
My HTML data is read from the database, this can be understood as the following code
?
1 2 3 4 |
<li><input type= "checkbox" Name= "UID" value= "1"/> user 1</li> <li><input "checkbox" Name = "UID" value= "2"/> user 2</li> <li><input type= "checkbox" Name= "UID" value= "3"/> User 3</li> < Li><input type= "checkbox" Name= "UID" value= "4"/> User 4</li> |
jquery Code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17-18 |
var mt4ids = []; $ (' input[name=uid] '). each (the function () {if (this.checked) {Mt4ids.push ($ (this). Val ());}); data = {mt4Ids:JSON.stringify (mt4ids)}; var pUrl = "/a/manageuser.html"; $.post (PURL, data, function (data) {if (Data.state = 1) {alert (data.msg); location.href = "/h/permission.html";} else{alert ("Operation failed");}}, ' JSON '; |
PHP code
?
1 2 3 4 5 6 7 8 9 10 11 12-13 |
$MT 4Ids =!empty ($_post[' mt4ids '])? $_post[' Mt4ids ']: false; $stripMt 4Ids = preg_replace ('/[' []]/', ', ', $mt 4Ids); $MT 4IDSTOARR = Explode (', ', $stripMt 4Ids); foreach ($mt 4IdsToArr as $uid) {Permission_relation::add ($uid, $gid);} $data = Array (' state ' => 1, ' msg ' => ' Operation succeeded ' ); echo Json_encode ($data); return false; $gid can ignore |
I hope this article will help you with your PHP program design.