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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用