【问题标题】:After ajax success show child table in if condition in ajax successajax成功后在ajax成功的if条件中显示子表
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 不,如果条件中的数据为 2,我想显示子表
    • 查看你在哪里执行函数 Example on : stage2.php 例如if (insert query successful on page stage2.php) {echo "2"} else { echo "0" }; aap 2 ke alawa kucch bhi print nahi karegi warna output nahi ayega data's meaning is out put of ajax calling page then ` if ($variable == 2 ){ // statement }`
    • 给我看看stage2.php的代码,我可以告诉方法
    • 看到不要,重复不要直接使用 ajax > 像我们使用表单发送值一样手动发送值到 stage2.php >>> 看看它在 stage2.php 上产生的成功和失败输出>>> 相应地进行回显/输出 >> 在成功执行时它必须只产生“2”,否则它将无法工作
    • 好的,我如何发送 stage2.php ?
    猜你喜欢
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多