jquery Gets the value of multiple checkboxes asynchronously submitted to PHP

Source: Internet
Author: User

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

Related Article

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.