【问题标题】:Ajax try to update data from table but in other lines not workAjax 尝试从表中更新数据,但在其他行中不起作用
【发布时间】:2021-06-11 01:53:27
【问题描述】:

我通过 ajax 更新表中的数据信息,但只使用第一行,其他行不起作用,这是我的 ajax:

$(document).ready(function(){
    $('#table').on('change', 'input', function () {
        var test={
            "test1": $("#test1").val(),
            "test2":$("#test2").val()
        }
        $.ajax({
            method: "POST",
            url:    "data.php",
            data: alta,
            async:true,
            cache:false,
            success : function(response){
            if(response=="1"){
                alert("done");
            } 
            else{
                alert("sad");
            }
            },
            error : function(error) {
                alert(error);
            }
        });
    });
});

如何更新表格中的其他行?

【问题讨论】:

  • 此代码不会更新任何内容。见minimal reproducible example
  • 是的,我没有放更新语句,但是这样第二行就不会执行 Ajax

标签: php html jquery ajax


【解决方案1】:

您必须指定具有唯一 id 的行,否则您需要使用此关键字来获取特定的数据行。

【讨论】:

  • 如何获取具体行?
  • 你使用的是数据表还是简单表?
  • 我用的是简单表
  • 请试试这个代码 document.getElementById("table").rows[i].cells[j].innerText;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-01
  • 1970-01-01
  • 2013-08-23
  • 2018-03-11
  • 2022-06-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多