dongshu4755 2017-04-04 15:12
浏览 48
已采纳

通过表中的ajax为特定行发送变量值

I am stuck on an issue concerning my ajax request. The goal is to have a table with a number of rows each including a button or a link that can be clicked to send a value in order to update the database. After this is done, the button or link should not be clickable anymore and be replaced by pure text on that specific row.

EDIT: Thanks to @Sagar Arora we have the working code now to send a specific variable value for a specific row, but we need a way to replace the button with pure text so one can see that it has been clicked.

For testing, I have the following 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> 

In my 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";

I am thankful for any help and tips!

  • 写回答

1条回答 默认 最新

  • douzao2590 2017-04-04 15:21
    关注

    SO this in the following way:

    <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
        } 
       });
    
    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧