mardi 19 février 2019

how to bind several selctors in jquery to specific data in only one ajax

I have a button which send me the values of input checkboxes via an ajax call.

<input type="checkbox" class="delete" value="PHP" /> PHP <br />  
<input type="checkbox" class="delete" value="ASP" /> ASP <br />

<button type="button" class="checkbox_value_delete">Delete</button>

The ajax:

$('.checkbox_value_delete').click(function(){  
       var checkboxes_delete = []; 
   $('.delete').each(function(){  
            if($(this).is(":checked")) {  
                 checkboxes_delete.push($(this).val());                      
            }  
   });
   checkboxes_delete = checkboxes_delete.toString();
     $.ajax({  
            url:"",  
            method:"POST",  
            data:{ checkboxes_delete:checkboxes_delete,
                    checkboxes_move:checkboxes_move },  
            success:function(data){  
                 $('.result').html(data);  
            }  
     });  
});

This works fine!

Now i want to add to more buttons and bind the selectors to the data in the same ajax call. is that possible or do i have to create 3 standalone ajaxes for this?.

Buttons:

<button type="button" class="checkbox_value_delete">Delete</button>  
<button type="button" class="checkbox_value_copy">Copy</button>  
<button type="button" class="checkbox_value_move">Move</button>  

Something liek below:

$('.checkbox_value_delete, checkbox_value_copy, checkbox_value_move ').click(function(){  
       var checkboxes_delete = []; // bind to 1st selector
       var checkboxes_copy = []; // bind to 2nd selector
       var checkboxes_move = []; // bind to 3rd selector
       // and so on...




Aucun commentaire:

Enregistrer un commentaire