jquery Gets the value of multiple checkboxes asynchronously submitted to PHP method
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:
?
My is that the data in the HTML is read from the database, in this can be understood as the following code
?
1 2 3 4 |
User 1User 2User 3User 4 |
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 (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 be ignored |
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1020891.html www.bkjia.com true http://www.bkjia.com/PHPjc/1020891.html techarticle jquery Gets the value of multiple checkboxes asynchronously submits a method to PHP by the example in this article that describes how jquery gets the values of multiple checkboxes asynchronously to the PHP method. Share to everyone for your reference. Specific ...