【发布时间】:2021-10-02 22:26:28
【问题描述】:
This is an HTML table with all buttons
单击表格行按钮中的按钮时,必须在后端 PHP 中更新状态,并且在 ajax 成功时我必须显示子表格
<table id="example" class="stripe row-border order-column" width="100%">
<thead>
<tr>
<th>Drawing</th>
<th style="display:none">Overview</th>
<th>Stage</th>
<th>Status</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr id="1">
<td><button type="button" class="button clarify" >Clarify</button></td>
<td><button type="button" class="button allot">Allott</button></td>
<td><button type="button" class="button start">Started/Pused</button></td>
<td><button type="button" class="button correctit">Quality Checking</button><td>
<td><button type="button" class="button send">Send</button></td>
</tr>
<tr id="2">
<td><button type="button" class="button clarify" >Clarify</button></td>
<td><button type="button" class="button allot">Allott</button></td>
<td><button type="button" class="button start">Started/Pused</button></td>
<td><button type="button" class="button correctit">Quality Checking</button><td>
<td><button type="button" class="button send">Send</button></td>
</tr>
</tbody>
</table>
这里是每次点击按钮状态都必须更新的 ajax 调用,如果按钮状态或数据为 == 2,那么我想显示子表
$(".button").click(function() {
$this = $(this);
//alert("am button");
var drawingid = $(this).closest('tr').attr('id'); // table row ID
var stage_id = $(this).closest('tr').find('.button').val();
// alert(stage_id);
$.ajax({
type: "POST",
url: "stage2.php",
dataType: "json",
data: {
"drawingID": drawingid,
"stage_ID": stage_id
},
success: function(data) {
alert(data);
if ( data == 2) {
**//here if the data is == 2 then show child table with dropdown** $this.parent().parent().find('.button').val(data);
$this.parent().parent().find('.button').html('Allott').addClass('allot').removeClass('clarify');
var tr = $(this).closest('tr');
id = $(this).closest('table').attr('id');
table = $('#' + id).DataTable();
var row = table.row(tr);
// Open this row
row.child(format(row.data(), id)).show();
tr.addClass('shown');
}
}
});
});
【问题讨论】:
标签: php html jquery mysql ajax