我堅持關於我的Ajax請求的問題的具體行。 的目標是有一個表與許多各包括一個按鈕或可點擊,以便更新數據庫發送值的鏈接行。完成此操作後,該按鈕或鏈接不應再次可點擊,並由該特定行上的純文本替換。通過AJAX在表發送變量值
編輯:感謝@Sagar Arora我們現在有工作代碼發送特定行的特定變量值,但我們需要一種方法來替換純文本的按鈕,以便可以看到它已被點擊。
爲了測試,我有以下potatoe.php:
// Several table-rows before and after
// Problem is, the class "paid_button" also belongs to the other buttons in every other
// table row, but I want to adress them specifically to get the id of that row for the ajax
<td><button name="paid" value="<?php echo $id; ?>" class="paid_button">Bezahlt</button></td>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="../js/global.js"></script>
在我global.js
$(document).on("click",".paid_button",function(){
var current_element = $(this);
$.ajax({
type: "POST",
url: "https://www.xxx",
data: { 'paid': current_element.attr("value")},
success: function(data){
alert("ok");
this.attr("disabled","disabled");//this will disable the clicked button
}
});
});
updatePotatoe.php:
// the update database query and execution (is already doing fine)
$request_id = $_POST['request_id'];
echo "test $request_id test";
我感謝所有幫助和提示!
檢查我的答案。這將解決你的問題。 –