Jquery returns multiple checkbox values and submits them to php asynchronously. Jquery gets the values of multiple checkboxes and submits them to php asynchronously. This document describes how jquery gets the values of multiple checkboxes and submits them to php asynchronously. Share it with you for your reference. How does jquery obtain the values of multiple checkboxes and submit them to php asynchronously?
This example describes how jquery asynchronously submits multiple checkbox values to php. Share it with you for your reference. The specific implementation method is as follows:
Html code:
?
My data in html is read from the database and can be understood as the following code:
?
1 2 3 4 |
User 1 User 2 User 3 User 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 |
$ Mt4Ids =! Empty ($ _ POST ['mt4kids'])? $ _ POST ['mt4kids']: false; $ StripMt4Ids = preg_replace ('/[\ "\ [\]/','', $ mt4Ids ); $ Mt4IdsToArr = explode (',', $ stripMt4Ids ); Foreach ($ mt4IdsToArr as $ uid ){ Permission_relation: add ($ uid, $ gid ); } $ Data = array ( 'Status' => 1, 'MSG '=> 'Operation successful' ); Echo json_encode ($ data ); Return false; // $ Gid can be ignored |
I hope this article will help you with php programming.
Examples in this article describes how jquery asynchronously submits multiple checkbox values to php. Share it with you for your reference. Details...