异步和数据表请求的问题

时间:2019-10-16 11:34:52

标签: ajax datatable

我正在使用数据表进行表分页和查找。 在此表中,我可以稍后编辑并更新我发出异步请求的表数据。到目前为止很好,但是在使用异步请求对表行执行更新之后,该行离开表或返回更新后的数据。 但是然后,如果我使用datatable函数进行表搜索以进行搜索或分页,则行会根据所做的更新返回或不返回更新的信息,

代码:

<table class="table table-responsive" id="employee_table1"> 
<thead>  
<tr>
<th>Pedido</th>
<th>Data</th>
<th>Valência</th>
<th>Ação</th>
</tr> 
</thead>
<tbody>     
<?php  do{ ?>
<tr id="<?php echo $produto1["Id"]; ?>">
<td><a class="view_data1" ><?php echo $produto1["Id"]; ?></a></td> 
<td><?php echo $produto1["DataRegisto"]; ?></td> 
<td><?php echo $produto1["Destino"]; ?></td>
<td><button type="button" data-id="<?php echo $produto1["Id"]; ?>"  data-target="#add_data_Modal4" class="btn btn-warning btn-sm edit_data1" ><span class="glyphicon glyphicon-pencil"></span></button></td> 
</tr>     
<?php } while($produto1 = $result1->fetch_assoc()); ?>
</tbody>    
</table>

使用“编辑”按钮调用模态进行编辑。在这种模式下,我有写更新的按钮:

<button type="button" class="btn btn-success" onclick="inserir_registo1();">Gravar</button>

然后发出异步请求,我在insert_register1()函数中执行此操作:

function inserir_registo1()
{  

    var dadosajax = {
        'Id' : $("#Id3").val(),
        'DataTermino' : $("#DataTermino1").val(),
        'Tratamento' : $("#Tratamento1").val(),
        'Estado' : $("#Estado3").val()
    };
    $.ajax({
        url: './resolucaomanutencao4',
        type: 'POST',
        cache: false,
        data: dadosajax,
        error: function(){
          $(".error_message").removeClass('hide');
        },
        success: function(result)
        { 
        $("#add_data_Modal4").modal("hide");
        $.ajax({
           url: './atualizarmanutencao4',
           type: 'get',
           dataType: 'json',
           success: function(data){
             var linha = ``; 
             for(let item of data){ 
             linha += `<tr id=${ item.Id }> 
             <td><a class="view_data1">${ item.Id }</a></td>             
             <td>${ item.DataRegisto }</td> 
             <td>${ item.Destino }</td>      
             <td><button type="button" data-id="${ item.Id }"  data-target="#add_data_Modal4" class="btn btn-warning btn-sm edit_data1" ><span class="glyphicon glyphicon-pencil"></span></button></td>
             </tr>`;
              $("#employee_table1 tbody").html(linha);           
             } 

             }

            });
        }       
    });

}

它打算在insert_register1()函数成功完成后使用异步搜索更新表之后,数据表将返回已使用更新更新的数据。

0 个答案:

没有答案