Codeigniter中的数据表警告:请求的未知参数' 0' 0第0行

时间:2017-03-01 09:50:19

标签: php jquery codeigniter datatables

我是jquery和codeigniter的完全新手。我已经在类似的论坛中阅读了可能的解决方案,但我无法弄清楚如何在我的代码中实现它们。这是查看代码。

$(document).ready(function() {

      $('select').chosen({
        disable_search_threshold: 10,
        allow_single_deselect: true
      });

      $('#search_results tbody').empty();

      var table = $('#search_results').DataTable();


      $('#search_documents_form').on('submit', function(event) {
          event.preventDefault();

          table.clear();

          $.ajax({
            method: 'POST',
            url: '<?php echo base_url($this->uri->uri_string())?>',
            data: {
              'search_documents': '1',
              'location': $('#location').val(),
              'document_type': $('#document_type').val(),
              'search_terms': $('#search_terms').val()

            }
          }).success(function(data) {
              var result = $.parseJSON(data);

              if (result.length > 0) {


                $('.total_results').empty();
                $('.total_results').append(' - ' + result.length + ' results');

                $.each(result, function(data) {


                  table.row.add([
                    this.document_branch,
                    this.document_type,
                    this.document_name,
                    this.document_update_date,
                    this.document_expiry_date,
                    '<a href="' + this.document_path + '" target="_blank"><span class="fa fa-arrow-down"></span></a>'
                  ]).draw();

                });

              } else {

                $('#search_results tbody').empty();

                $('.total_results').empty();
                $('.total_results').append();
                $('#search_results tbody').append('<tr><td colspan="6"><center>  <
                  h3 > No Results < /h3></center > < /td></tr > ');
                }

              });
          });
      });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <form class="form-horizontal" id="search_documents_form" action="<?php echo base_url($this->uri->uri_string());?>" method="POST">
    <input type="hidden" name="search_documents" value="1">
    <div class="col-lg-12">
      <legend>Search Documents</legend>
      <div class="panel panel-primary">
        <div class="panel-heading">Search Critera</div>
        <div class="panel-body">
          <div class="row">
            <div class="col-lg-6">
              <!-- Select Basic -->
              <div class="form-group">
                <label class="col-md-4 control-label" for="selectbasic">Location</label>
                <div class="col-md-8">
                  <select id="location" name="location" class="form-control">
                                <option></option>
                                <?php foreach($branches as $branch_type => $branches_by_type){?>
                                    <optgroup label="<?php echo $branch_type?>">
                                    <?php foreach($branches_by_type as $branch_name){?>
                                        <option value="<?php echo $branch_name['branch_index']?>"><?php echo $branch_name['branch_name']?></option>
                                    <?php }?>
                                    </optgroup>
                                <?php }?>
                            </select>
                </div>
              </div>
            </div>
            <div class="col-lg-6">
              <!-- Select Basic -->
              <div class="form-group">
                <label class="col-md-4 control-label" for="document_type">Document Type</label>
                <div class="col-md-8">
                  <select id="document_type" name="document_type" class="form-control">
                                <option></option>
                                 <?php foreach($document_types as $type){?>
                                    <option><?php echo ucfirst($type['document_type']);?></option>
                                 <?php }?>
                            </select>
                </div>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-lg-6">
              <!-- Text input-->
              <div class="form-group">
                <label class="col-md-4 control-label" for="search_terms">Search Terms</label>
                <div class="col-md-8">
                  <input id="search_terms" name="search_terms" type="text" placeholder="Search Terms" class="form-control input-md">

                </div>
              </div>
            </div>
            <div class="col-lg-6">
              <div class="form-group">
                <div class="col-md-8 col-md-offset-4">
                  <button type="submit" class="btn btn-primary pull-right">
                                    Search
                            </button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
  </form>
  </div>
  <div class="col-lg-12">
    <div class="panel panel-default" style="margin-bottom: 75px;">
      <div class="panel-heading">Search Results <span class="total_results"></span></div>
      <div class="panel-body">

        <table class="table table-bordered table-hover table-striped" id="search_results">
          <thead>
            <th style="width: 200px;">Branch</th>
            <th>Document Type</th>
            <th>Document Name</th>
            <th style="width: 75px;">Updated</th>
            <th>Expiry Date</th>
            <th style="width: 50px;">Action</th>
          </thead>
          <tbody>
            <tr>
              <td colspan="6">
                <center>
                  <h3>Please enter search criteria</h3>
                </center>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>

单击警告后,可能会多次,结果会在表格中正确显示。有人可以帮忙吗?

0 个答案:

没有答案