我有一个 index.php ,用户可以预留很多。该按钮来自另一页 2dmap_func.php ,然后显示在id" detalye"在ajax调用执行后的index.php中。
的index.php
</div>
<script>
$(document).ready(function(){
$('#reserve').click(function(){
alert('ok');
});
var lnk2;
var lot
$('[href]').click(function(){
lnk2 = '';
lot='';
lnk2 = $(this).attr('href');
if (lnk2.charAt(1) == "b") {
lot = lnk2;
$.ajax({
url: "2dmap_func.php",
method: "POST",
dataType: "text",
data: {lot:lot},
success: function(data) {
$('#detalye').html(data);
}
});
}
});
});
</script>
2dmap_func.php
$sql = "SELECT * FROM lots WHERE link='$_POST[lot]'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$sql2 = "SELECT * FROM reservation WHERE lot='$_POST[lot]'";
$result1 = $conn->query($sql2);
echo '<div id="head_d">LOT DETAILS</div>
<div id="content_d">
<div id="location"><h3>Block:</h3> '.$row['block'].' • <h3>Lot:</h3> '.$row['lot'].'</div>
<div id="type">Type: '.$row['type'].'</div>
<div id="dimensions">North: '.$row['dimension_north'].'• East: '.$row['dimension_east'].'• West: '.$row['dimension_west'].'• South: '.$row['dimension_south'].'</div>
<div id="button">'.(($result1->num_rows < 1) ?'<button id="reserve">Reserve this Lot</button>':'This lot is currently not available for Reservation.').'</div>
</div>';