Ajax,复选框和PHP

Needing a little help please. I have this: enter image description here

Which allows users to select more than one item, I need to gather if its selected and what the value is which is the title of the item in this case.

I also have this ajax currently:

  $('.box').on('change', function(event) {


         var valueName = $('#box').val();



            var checked = $('input[name=checked]:checked');
             if( checked.length > 0 ) {
                  var checkValues = checked.map(function(){
                        return $(this).val();
                    }).get();                        
                     $.ajax({
                          url: 'accessories_post.php',
                          type: 'post',
                          data: { checked: checkValues },
                          success:function(data){ console.log(data); }
                     });
                }

Which posts to accessories_post.php which has

 print_r($_POST['checked']);

But then when I want to grab this data and put into a variable i need to then send via mail any ideas why im not getting anything for this.

Instead of the .map function, you can simply do:

 checkValues = '';
 $('input[name="checked"]:checked').each(function(){
     checkValues+=$(this).val()+",";
 });
 //this is to remove the extra comma , at the end of the string
 checkValues = checkValues.substring(0,(checkValues.length-1));

I've concatenated the checkbox values, so $_POST['checked'] will return values like title,title2 etc.

And regarding the increment of id value that you had asked, you can do something like:

$i=0;
//your loop statement starts
 echo "<input type='checkbox' id='box{$i}' name='checked'>";
 $i++;
//loop ends