Select复选框->点击按钮->更新table值
Select checkbox - > click button - > update table values
重新尝试列 下的初始值将为空白。一旦我们 select 某些行的复选框并单击按钮 reattempt ,我想更新 column reattempt
的值以重新尝试。
html
<button id="reattempt">reattempt</button>
<tr>
<th class="table-header">Reattempt</th>
</tr>
<tr>
<td id="<?php echo $orderrecords[$k]["tracking_id"];?>reattempt">
<?php echo $orderrecords[$k]["reattempt"]; ?>
</td>
</tr>
脚本
$('#reattempt').click(function() {
var selected = [];
$('.assigneeid-order:checked').each(function() {
selected.push($(this).val());
$('.assigneeid-order').prop('checked', false);
});
var jsonString = JSON.stringify(selected);
$.ajax({
type: 'POST',
url: 'reattempt.php',
data: { data: jsonString },
success: function(response) {
response = $.parseJSON(response);
$.each(response, function(index, val) {
$('#' + index + '').html(val);
$('#' + index + 'reattempt').html(val.reattempt);
});
}
});
});
reattempt.php
$data = json_decode(stripslashes($_POST['data']));
foreach($data as $id)
{
$orderid = $id;
$reattempt='';
$sqlecom = "UPDATE do_order set reattempt = '$reattempt' where tracking_id=".$orderid;
$db_handleecom = new DBController();
$resultecom = $db_handleecom->executeUpdate($sqlecom);
$response[$orderid] = [ 'reattempt' => $reattempt ];
}
echo json_encode($response);
结果
值未更新,以下是回复:
您正在使用 $('.assigneeid-order').prop('checked', false);
将所有复选框设置为未选中,请使用 $(this).prop('checked', false);
进行编辑,这将指向循环中的当前复选框。另外,用缺少的 TDs
更新你的 html
您的代码中没有任何内容正在更新,因为在您的 php 文件中,您正在设置 $reattempt='';
并且没有任何进一步的更改,您将其返回为空..所以,您不能期望不是空值..
重新尝试列 下的初始值将为空白。一旦我们 select 某些行的复选框并单击按钮 reattempt ,我想更新 column reattempt
的值以重新尝试。
html
<button id="reattempt">reattempt</button>
<tr>
<th class="table-header">Reattempt</th>
</tr>
<tr>
<td id="<?php echo $orderrecords[$k]["tracking_id"];?>reattempt">
<?php echo $orderrecords[$k]["reattempt"]; ?>
</td>
</tr>
脚本
$('#reattempt').click(function() {
var selected = [];
$('.assigneeid-order:checked').each(function() {
selected.push($(this).val());
$('.assigneeid-order').prop('checked', false);
});
var jsonString = JSON.stringify(selected);
$.ajax({
type: 'POST',
url: 'reattempt.php',
data: { data: jsonString },
success: function(response) {
response = $.parseJSON(response);
$.each(response, function(index, val) {
$('#' + index + '').html(val);
$('#' + index + 'reattempt').html(val.reattempt);
});
}
});
});
reattempt.php
$data = json_decode(stripslashes($_POST['data']));
foreach($data as $id)
{
$orderid = $id;
$reattempt='';
$sqlecom = "UPDATE do_order set reattempt = '$reattempt' where tracking_id=".$orderid;
$db_handleecom = new DBController();
$resultecom = $db_handleecom->executeUpdate($sqlecom);
$response[$orderid] = [ 'reattempt' => $reattempt ];
}
echo json_encode($response);
结果
值未更新,以下是回复:
您正在使用 $('.assigneeid-order').prop('checked', false);
将所有复选框设置为未选中,请使用 $(this).prop('checked', false);
进行编辑,这将指向循环中的当前复选框。另外,用缺少的 TDs
您的代码中没有任何内容正在更新,因为在您的 php 文件中,您正在设置 $reattempt='';
并且没有任何进一步的更改,您将其返回为空..所以,您不能期望不是空值..