jquery Gets the value of multiple checkboxes asynchronously to the method that is submitted to PHP, Jquerycheckbox
This example describes how jquery gets the values of multiple checkboxes asynchronously to the PHP method. Share to everyone for your reference. The implementation method is as follows:
HTML code:
<?= $item [' mtaccount_id ']?> <?= $item [' account_id ']?> <?= $item [' account_name ']?> <?= $item [' Server ']?> <?= $item [' Platform ']?>
My is that the data in the HTML is read from the database, in this can be understood as the following code
User 1User 2User 3User 4
jquery Code:
var mt4ids = []; $ (' input[name=uid] '). each (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 (', ', $ Stripmt4ids), foreach ($mt 4IdsToArr as $uid) { permission_relation::add ($uid, $gid);} $data = Array ( ' state ' = = 1, ' msg ' = ' operation succeeded '); Echo Json_encode ($data); return false;//$gid negligible
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1021083.html www.bkjia.com true http://www.bkjia.com/PHPjc/1021083.html techarticle jquery Gets the value of multiple checkboxes asynchronously to the PHP method, Jquerycheckbox This example describes how jquery gets the values of multiple checkboxes asynchronously to the PHP method. Share to everyone ...