hello,
im just learning jquery and ajax via YT, and i tried to create a form with combo box, and show records from database based on combo box
after that, i want to store the data to the session
i already created the form that showing the records and already worked, but the button that i created that for store to the session, the ajax is not working.
ajax3.php (index)
<form action="cari.php" method="POST">
<select name="kamar">
<option value="regular single">Regular Single Rp 99.000</option>
<option value="regular double">Regular Double Rp 120.000</option>
<option value="family single">Family Single Rp 127.500</option>
<option value="family double">Family Double Rp 150.000</option>
<option value="vip single">V.I.P Single Rp 170.000</option>
<option value="vip double">V.I.P Double Rp 200.000</option>
</select>
<br>
<button type="submit" name="submit">Submit</button>
</form>
<br>
<div id="tampil"></div>
<script type="text/javascript">
$(document).ready(function(){
$('form').on('submit', function(e)
{
e.preventDefault();
$.ajax({
type: $(this).attr('method'),
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data){
$("#tampil").html(data);
},
});
$('.simpanData').on('submit', function(e)
{
e.preventDefault();
$.ajax({
type: "get",
url: $(this).attr('href'),
data: $(this).serialize(),
success: function(data){
$("#tampil").html(data);
},
});
});
});
});
here is cari.php (searching)
<?php
include "koneksi.php";
$jenis = $_POST['kamar'];
$sql= "select * from kamar where jkamar = '$jenis' ";
$result = mysqli_query($conn, $sql);
?>
<table>
<?php
if(mysqli_num_rows($result) > 0)
{
while ($data = mysqli_fetch_array($result))
{
$link_simpan = "<a class='simpanData' href='simpan2.php?nokmr=".$data['nokamar']."'>Simpan</a>";
?>
<tr>
<td value="<?php echo "nokamar = $data[nokamar]"; ?>"><?php echo $data['nokamar'];?></td>
<td><?php echo $link_simpan ?></td>
</tr>
<?php
}
}
else
{
echo "no more data!";
}
?>
</table>
any help will be appreciated, thanks