【问题标题】:Is it possible to show a table row as soon as the data gets inserted with out inserting in codeigniter?插入数据后是否可以在不插入codeigniter的情况下立即显示表格行?
【发布时间】:2023-03-25 13:20:01
【问题描述】:

是否可以在插入数据后立即显示表格行而不插入 codeigniter ?我不想使用套接字,但我也没有找到解决方案,因为当我使用 ajax 时,div 会自我复制。

【问题讨论】:

  • 您的问题不清楚。另外,你能添加一些代码吗?
  • 您是否希望在用户发布的同一选项卡中更新表格行?还是不同的选项卡/用户表?

标签: php ajax database codeigniter real-time


【解决方案1】:

您可以使用 ajax 来做到这一点。

我们在这里需要 2 个 ajax 调用。 1. 用于填充数据。 2.用于插入数据。

成功插入数据后,您可以启动列表功能。 代码示例如下。

function populateList(){

   var resultHtml = '';

    $.ajax({
        type: "POST",
        dataType: "json",
        url: 'api/for/getting/list/of/data',
        data:{},
        cache: false,

    success:function(response) {


        $.each(response.list,function(key,val){
            resultHtml += '<tr>';
            resultHtml += val.name;
            resultHtml += '</tr>';
            resultHtml += '<tr>';
            resultHtml += val.mobile;
            resultHtml += '</tr>';
            resultHtml += '<tr>';
            resultHtml += val.address;
            resultHtml += '</tr>';
        })

        //Populate in in the <tbody> of the table
        $('#list_table').html(resultHtml);

    }
  });
}




 $('#insert_buttom').click(function(){
        $.ajax({
        type: "POST",
        dataType: "json",
        url: 'api/for/inserting/data',
        data:{},// pass all the data here
        cache: false,

    success:function(response) {
       populateList();
    }
  });
 })

【讨论】:

    猜你喜欢
    • 2015-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    相关资源
    最近更新 更多