This is my code I using this to send my form to another page called prueba_dos.php
$(document).on('ready',function(){
$('#enviar').click(function(){
event.preventDefault();
var url = "prueba_dos.php";
$.ajax({
type: "POST",
url: url,
data: $("#formulario").serialize(),
success: function(data)
{
$('#resp').html(data);
}
});
});
});
Just like this you return own id or name as you want but you targeting all of them by using class:
$('.buttons').click(function(){
console.log($(this).attr('id')); //id button clicked
console.log($(this).attr('name')); //name button clicked
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<button id="test_id" name="test" class="buttons">test</button>
<button id="test_id1" name="test1" class="buttons">test1</button>
<button id="test_id2" name="test2" class="buttons">test2</button>
<button id="test_id3" name="test3" class="buttons">test3</button>
<button id="test_id4" name="test4" class="buttons">test4</button>
</div>