Ajax taking only the first id

1
Hello, I am updating a list with arrays and php, passing two presence parameters (ckeckbox) that returns true or false and id in hidden, but the id does not proceed in the loop, getting in the first id in the two values:

array(2) {
  ["id"]=>
  array(2) {
    [0]=>
    string(1) "2"
    [1]=>
    string(1) "2"
  }
  ["presenca"]=>
  array(2) {
    [0]=>
    string(5) "false"
    [1]=>
    string(4) "true"
  }

	$(document).ready(function(){
		 $('#btn_update').click(function(){  
		 
		   var id = [];
		   var presenca = [];
		
		   $(':checkbox').each(function(i){
		   
		    presenca[i] = $('#permissao').val(); 
		    id[i] = $('#id').val();
			    if(presenca[i] == this.checked){
			    	this.checked = true;
			    	presenca[i] = this.checked;
			    	
			    }else{
			    	this.checked = false;
			    	presenca[i] =this.checked;
			    	
			    }
		   });
		   
		  
		    $.ajax({
		     url:'<?php echo WEBROOT; ?>/sistema/modulos/processa-permissao.php',
		     method:'POST',
		     data:{id:id, presenca:presenca},
		     success:function()
		     {
		      alert('update ok'); 
		     }
		     
		    });
		   
		 });

The intention is whether or not to mark ajax by inserting the update in looping.

What am I missing?

    
asked by anonymous 08.01.2018 / 13:18

1 answer

1

[Solved] I put an attribute in the check box and I used attr (); Only the question remains, type = 'hidden' causes unique effect on the gift?

$(document).ready(function(){
		 $('#btn_update').click(function(){  
		 
		   var id = [];
		   var presenca = [];
		
		   $(':checkbox').each(function(i){
		   
		    presenca[i] = $('#permissao').val(); 
		    //id[i] = $('#id').val(); Aqui está o erro
                      id[i] = $(this).attr("idpega");
			    if(presenca[i] == this.checked){
			    	this.checked = true;
			    	presenca[i] = this.checked;
			    	
			    }else{
			    	this.checked = false;
			    	presenca[i] =this.checked;
			    	
			    }
		   });
		   
		  
		    $.ajax({
		     url:'<?php echo WEBROOT; ?>/sistema/modulos/processa-permissao.php',
		     method:'POST',
		     data:{id:id, presenca:presenca},
		     success:function()
		     {
		      alert('update ok'); 
		     }
		     
		    });
		   
		 });
<input type="checkbox"  id="permissao" '.$permission.' value="'.$relaciona.'" idpega="'.$user_id.'" >
<!-- Criei um atributo para o mesmo checkbox colocando o id -->
    
08.01.2018 / 16:32