我正在尋找基於點擊在PHP頁面上的鏈接改變div的內容。鏈接是通過循環創建的,我需要通過URL傳遞幾個參數。 div也是通過循環創建的,所以div的id將是可變的。我在使用AJAX時遇到了麻煩。AJAX在點擊PHP循環內更改div值
下面是我的PHP:
<?php
if ($result3->num_rows > 0) {
while($row3 = $result3->fetch_assoc()) {
$tripDestination = $row3["tripDestination"];
$sessionID = $row3["$sessionID"];
$price = $row3["price"];
echo "<a href=\"#\">" . $tripDestination . ' - ' . $price . "</a>";
echo "<br />";
echo "<div id=\"trips\"></div>";
}
}
?>
我需要通過在URL中兩個變量:會話ID和tripDestination。我能夠加載靜態內容,但它需要動態。這裏是我的AJAX到目前爲止
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url: "sqlUpload.php?sessionID=35&tripDestination=SFO", success: function(result){
$("#div1").html(result);
}});
});
});
</script>
在此先感謝!
按鈕的Click處理程序需要以某種方式知道哪個''鏈接它是su致力於解決。它是如何做到的?每個鏈接是否會有一個按鈕? –
或者你真的想要點擊處理程序被附加到鏈接本身? –