通过AJAX在表发送变量值

问题描述:

我坚持关于我的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"; 

我感谢所有帮助和提示!

+0

检查我的答案。这将解决你的问题。 –

所以这通过以下方式:

<button name="paid" class="paid_button" value="$id" >Support</button> 

$(document).on("click",".paid_button",function(){ 

var current_element = $(this); 
    $.ajax({ 
    type: "POST", 
    url: "https://www.xxx.php", 
    data: { 'paid': current_element.attr("value")}, 
    success: function(data){ 
    alert("ok"); --> just for testing, I actually want to return values 
    this.attr("disabled","disabled");//this will disable the clicked button 
    } 
    }); 


}); 
+0

嗨Sagar,谢谢你的帮助!我用你的建议编辑了我原来的文章,并且发布了一些我的代码。它仍然没有虽然@ Franky2207只是警报(“东西”)下点击代码的工作,当我按一下按钮没有任何反应:(。 – Franky2207

+1

并检查在浏览器控制台是有一些错误,请让我知道? –

+0

控制台了我下面的错误(没有提示弹出):'语法错误:缺少变量名VAR此= $(本);'不过,我现在解决了我原来的问题,但我仍然停留在唯一adressing表行 - 是,即使可能吗?我编辑了我原来的帖子。晚安! – Franky2207