Когда я выбираю данные с помощью AJAX, нумерация таблиц начальной загрузки и поиск не работают - PullRequest
1 голос
/ 02 апреля 2019

Я создаю небольшой проект с использованием PHP, MySQL, Ajax и Bootstrap.Когда я выбираю данные с помощью PHP include и помещаю их внутрь тега body table, нумерация таблиц Bootstrap и поиск работают нормально, но когда я выбираю данные с помощью AJAX и добавляю их в тело таблицы с помощью ID, пагинация и поиск не работают,

Начальная страница поиска и поиск работают с этим кодом:

<!-- Table -->
<div class="card shadow mb-4">
  <div class="card-header py-3">
    <center>
      <h6 class="m-0 font-weight-bold text-primary">LIST OF STOCKS</h6>
    </center>
  </div>
  <div class="card-body">
    <div class="table-responsive">
      <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
        <thead>
          <tr>
            <th>ASSET TAGS</th>
            <th>PARTICULARS</th>
            <th>STATUS</th>
            <th>PREVIOUS USER</th>
            <th>OPTION</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th>ASSET TAGS</th>
            <th>PARTICULARS</th>
            <th>STATUS</th>
            <th>PREVIOUS USER</th>
            <th>OPTION</th>
          </tr>
        </tfoot>
        <tbody><?php include('../functions/stocks_fetch.php'); ?></tbody>
      </table>
    </div>
  </div>
</div>
<!-- End of Table -->

// Call the dataTables jQuery plugin
$(document).ready(function() {
  $('#dataTable').DataTable();
});

И не работают с этим кодом:

<!-- Table -->
<div class="card shadow mb-4">
  <div class="card-header py-3">
    <center>
      <h6 class="m-0 font-weight-bold text-primary">LIST OF STOCKS</h6>
    </center>
  </div>
  <div class="card-body">
    <div class="table-responsive">
      <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
        <thead>
          <tr>
            <th>ASSET TAGS</th>
            <th>PARTICULARS</th>
            <th>STATUS</th>
            <th>PREVIOUS USER</th>
            <th>OPTION</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th>ASSET TAGS</th>
            <th>PARTICULARS</th>
            <th>STATUS</th>
            <th>PREVIOUS USER</th>
            <th>OPTION</th>
          </tr>
        </tfoot>
        <tbody id="tbody"></tbody>
      </table>
    </div>
  </div>
</div>
<!-- End of Table -->

//FETCH DATA TO DISPLAY
function fetch(){
    $.ajax({
        method: 'POST',
        url: 'functions/stocks_fetch.php',
        success: function(response){
            $('#tbody').html(response);
        }
    });
}

<!-- MY NEW WORKING AJAX CODE -->

/FETCH DATA TO DISPLAY
function fetch(){
    $.ajax({
        method: 'POST',
        url: 'functions/stocks_fetch.php',
        success: function(response){
            $('#tblbody').html(response);

            $(document).ready(function() {
                $('#dataTable').DataTable();
              });       
        }
    });
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...