doutouhe5343 2019-01-18 17:13
浏览 57

编辑表行php ajax

I am trying to edit this table row of an inline edit table. I am able to pass data from my js file to my PHP file for the query. The issue I am having is with getting the data from the table row. Every method I have tried to put table data in a JavaScript variable to send through ajax is not working. I have tried echoing the data, json_encode, using selectors...

I am new to this so maybe I am making a minor mistake. But I am able to Delete passing the id through an href. I need to edit several table cells and pass the df id:

$df_id = $row['df_id'];    
echo '<td class="border-left text-center" id="cg_crit">'.$row['ContentGrammarCritical'].'</td>';
echo '<td class="text-center">'.$row['ContentGrammarMajor'].'</td>';
echo '<td class="text-center">'.$row['ContentGrammarMinor'].'</td>';
echo '<td class="border-left text-center" >'.$row['functionalCritical'].'</td>';
echo '<td class="text-center">'.$row['functionalMajor'].'</td>';
echo '<td class="text-center">'.$row['functionalMinor'].'</td>';
echo '<td class="border-left text-center" >'.$row['NonfunctionalCritical'].'</td>';
echo '<td class="text-center">'.$row['NonfunctionalMajor'].'</td>';
echo '<td class="text-center">'.$row['NonfunctionalMinor'].'</td>';

Here is my code.

The Edit Table

while($row=mysqli_fetch_assoc($result)) {
    $df_id = $row['df_id'];
    $convert_day = $row['df_date'];
    $day_date = strftime("%A",strtotime($convert_day));
    echo '<tr><td>'.$day_date.'</td>';
    echo '<td id="pr_name">'.json_encode($row['pr_name']).'</td>';
    echo '<td>'.$row['tcs_type'].'</td>';
    echo '<td class="text-center" id="rnd">'.$row['df_round'].'</td>';
    echo '<td class="border-left text-center" id="cg_crit">'.$row['ContentGrammarCritical'].'</td>';
    echo '<td class="text-center">'.$row['ContentGrammarMajor'].'</td>';
    echo '<td class="text-center">'.$row['ContentGrammarMinor'].'</td>';
    echo '<td class="border-left text-center" >'.$row['functionalCritical'].'</td>';
    echo '<td class="text-center">'.$row['functionalMajor'].'</td>';
    echo '<td class="text-center">'.$row['functionalMinor'].'</td>';
    echo '<td class="border-left text-center" >'.$row['NonfunctionalCritical'].'</td>';
    echo '<td class="text-center">'.$row['NonfunctionalMajor'].'</td>';
    echo '<td class="text-center">'.$row['NonfunctionalMinor'].'</td>';
    echo '<td  class="border-left" contenteditable="false"><div class="ticket-actions col-md-2">
    <div class="btn-group dropdown">
        <a type="button" class="btn dropdown-toggle btn-sm" data-toggle="dropdown">
        Manage
        </a>
        <div class="dropdown-menu">
        <a class="dropdown-item editbtn">
            <i class="fa fa-reply fa-fw"></i>Edit</a>
            <a class="dropdown-item cancelbtn" href="javascript:history.go(0)">
            <i class="fa fa-reply fa-fw"></i>Cancel</a>
            <button class="dropdown-item savebtn" id="">
            <i class="fa fa-check text-success fa-fw"></i>Save</button>
        <div class="dropdown-divider"></div>

        <a class="dropdown-item" href="DB/defect/delete_defect.php?id='. $df_id .'">
            <i class="fa fa-times text-danger fa-fw"></i>Delete</a>
        </div>
    </div>
    </div></td></tr>';
}

THE AJAX

$('.savebtn').click(function() {
    $.each(currentTD, function() {
        //alert("second if "+currentTD.html());
        $(this).prop('contenteditable', false).removeAttr("style");
        //var df_id = $(this).('#pr_name');
        var df_id2 = 
        var df_id3 = "45";
        console.log(df_id2);
        $.post("DB/defect/edit_defect.php", {
            df_id: df_id2,
            day_date: df_id3
        }, function(data) {
            console.log(data);
        });

        $('.editbtn').show();
        $('.savebtn').hide();
        $('.cancelbtn').hide();
    });
})
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c