选择复选框 - >点击按钮 - >更新表值

时间:2018-03-07 06:07:09

标签: jquery-plugins

重新尝试列下的初始值将为空白。在我们选中某些行的复选框并点击按钮重新尝试后,我想更新column reattempt的值以重新尝试。

enter image description here

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);

结果

值未更新,下面是回复:

enter image description here

1 个答案:

答案 0 :(得分:1)

您要设置所有复选框以取消选中$('.assigneeid-order').prop('checked', false);,请使用$(this).prop('checked', false);进行编辑,这将指向循环中的当前复选框。另外,用缺少的TD更新你的html

您的代码中没有任何内容正在更新,因为在您的php文件中,您正在设置$reattempt='';而没有任何进一步的更改,您将其返回为空..所以,您不能指望除了空值..