ajax成功后,在ajax成功中的if条件下显示子表

wz8daaqr  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(240)
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');
      }  
    }
  });
});
mftmpeh8

mftmpeh81#

在ajax中向0/1传递一个附加值,并使用“if”运行语句/函数

相关问题