I know that a code like this is used for sending data to php file without refreshing by using ajax, but this code only works for one form with some inputs, my problem is: I have a web page that in it there are 5 buttons and each button is related to different input, I want to send data with ajax without refreshing,for example when I click on button 1, it sends its own inputs and when I click button n it sends its own data, how can I do that?
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'led.php',
data: $('form').serialize(),
success: function () {
}
});
});
});
</script>
</head>
<body>
<form>
<input type='hidden' name="key" value="on">
<input name="key" type="submit" value="ON">
</form>
</body>
</html>