Ajax File
Create new php file named ajax.php as below:
<?php
$ids = $_POST['ids'];
print_r($ids);
foreach($ids as $id) {
echo '<br>'.$id;
}
?>
Index File
Create new php file named index.php as below:
<html>
<head>
<title>nilpointer.net</title>
<script src="js/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('#buttonDemo').click(function() {
$.ajax({
type: 'POST',
data: {
ids: [12, 34, 56, 78]
},
url: 'ajax.php',
success: function(data) {
$('#result').html(data);
}
});
});
});
</script>
</head>
<body>
<input type="button" value="Demo Ajax" id="buttonDemo">
<br>
<span id="result"></span>
</body>
</html>