我正在尝试编辑内联编辑表的该表行。我可以将数据从js文件传递到PHP文件进行查询。我遇到的问题是从表行获取数据。我尝试将表数据放入JavaScript变量以通过ajax发送的每种方法均无效。我尝试使用选择器回显数据json_encode
我对此很陌生,所以也许我犯了一个小错误。但是我能够删除通过href传递ID。我需要编辑几个表格单元格并传递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>';
这是我的代码。
编辑表
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>';
}
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();
});
})