How to asynchronously submit multiple checkbox values to php using jquery _ PHP Tutorial

Source: Internet
Author: User
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:

?

1

2

3

4

5

6

7

8

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...

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.