HTML code:
<TR> <TD><inputtype= "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 is that the data in the HTML is read from the database, in this can be understood as the following code
<Li><inputtype= "checkbox"name= "UID"value= "1" />User 1</Li><Li><inputtype= "checkbox"name= "UID"value= "2" />User 2</Li><Li><inputtype= "checkbox"name= "UID"value= "3" />User 3</Li><Li><inputtype= "checkbox"name= "UID"value= "4" />User 4</Li>
jquery Code:
1 varMt4ids = [];2$ (' input[name=uid] '). each (function() {3 if( This. Checked) {4Mt4ids.push ($ ( This). Val ());5 }6 });7data = {8 mt4Ids:JSON.stringify (mt4ids)9 };Ten varPURL = "/a/manageuser.html"; One$.post (PURL, data,function(data) { A if(Data.state = = 1){ - alert (data.msg); -Location.href = "/h/permission.html"; the}Else{ -Alert ("Operation failed"); - } -}, ' json ');
PHP code
1 $mt 4Ids= !Empty($_post[' Mt4ids ']) ?$_post[' Mt4ids ']:false;2 3 $stripMt 4Ids=Preg_replace(‘/[\"\[\]]/‘, ‘‘,$mt 4Ids);4 $mt 4IDSTOARR=Explode(‘,‘,$stripMt 4Ids);5 6 foreach($mt 4IDSTOARR as $uid){7Permission_relation::add ($uid,$gid);8 }9 $data=Array(Ten' state ' = 1, One' msg ' = ' Operation succeeded ' A ); - EchoJson_encode ($data); - return false;
$gid can be ignored
jquery gets multiple checkboxes of values asynchronously submitted to PHP