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:
<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
<li><input type= "checkbox" Name= "UID" value= "1"/> user 1</li> <li><input
"Type=" 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:
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
$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.