【问题标题】:PHP and AJAX - Append new data to a table, and new edit and delete buttons with the generated idPHP 和 AJAX - 将新数据附加到表中,以及使用生成的 id 的新编​​辑和删除按钮
【发布时间】:2018-12-30 17:28:16
【问题描述】:

首先,请原谅我的英语,我希望我能解释一下自己。

我想要做的是:我点击一个按钮 -> 用于引入新数据的表单并提交按钮(在数据库中生成一个 id)。

当我提交它时(我使用模式),新数据将附加到带有新附加编辑和删除按钮的表中......问题是我不知道如何将新 id 分配给这些按钮...

有什么提示或帮助吗?

编辑:

我在ajax之前有这个

var display = $('input[name="element_display"]').val(); 
var key = $('input[name="element_key"]').val(); 

获取我在表单中插入的那些值...我不知道如何对 ID 执行相同操作(数据库中的自动增量)。

在 Ajax 中我有这个:

'<td>'+ '<span class="btn btn-default edit_element" id=' + key + ' 
value="' + key + '">' + '<a href="'+$("#base_url").attr("valor") 
+"dictio/dictio_element/"+key+'" title="Edit">' +'<i 
class="material-icons">edit</i>' + '</a>' +'</span>' +'</td>' 

要绘制按钮,但我需要的是 ID,而不是键...

【问题讨论】:

  • 你以前做过什么?请把你的代码放在这里
  • 请添加一些相关代码,到目前为止您已经尝试过。
  • 我编辑了我的问题

标签: php mysql ajax database append


【解决方案1】:

将您的代码更改为以下内容

'<td>'+ '<span class="btn btn-default edit_element" id=' + key + ' 
value="' + key + '">' + '<a id="'.$IdVariable.'" href="'+$("#base_url").attr("valor") 
+"dictio/dictio_element/"+key+'" title="Edit">' +'<i 
class="material-icons">edit</i>' + '</a>' +'</span>' +'</td>' 

在 Jquery 中,您可以通过

获取点击的 id
$('.btn').click(function() {
    var id = $(this).attr('id');
    alert(id); //alert the button id
});

【讨论】:

    猜你喜欢
    • 2019-09-02
    • 2016-04-29
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    相关资源
    最近更新 更多