在数据表中设置ajax响应

时间:2015-06-03 06:54:08

标签: php ajax database

我的数据表文件就像我得到的结果是AJAX响应但是我无法在数据表中设置它自动设置在页面顶部的响应我已经在div中给了类但是我无法得到正确的结果:< / p>

<?php
  include 'header.php';
  include 'footer.php';

  if(isset($_REQUEST['delete_id']))
  {
      $delete_id = $_REQUEST['delete_id'];
      $query = "DELETE contact, address, addressgroup FROM contact, address, addressgroup WHERE contact.contact_id = '$delete_id'  AND address.contact_id = '$delete_id' AND addressgroup.contact_id='$delete_id'";
      $query = mysql_query($query);
  }
?>
<head>
  <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.2/js/jquery.dataTables.js"></script>
  <script type="text/javascript">
     $(document).ready(function() {
    $('#example').dataTable( {
        "pagingType": "full_numbers"
    } );
} );

var myarray;
function getcon() {
  myarray = [];
  myarray.push($(".group_id").val());
  $.ajax({
      type: "POST",
      url: "getcon.php",
      data: 'group_id=' + myarray.join(),
      success: function(data) {
          $('.group').html(data);
      }
  });
  return false;
}
</script>
</head>
<div class="wrapper row-offcanvas row-offcanvas-left">
  <?php include 'admin_leftside.php'; ?>
  <aside class="right-side">                
    <section class="content-header">
      <h1>Contact List</h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Contact List</li>
    </ol>
    </section>
<section class="content">
<div class="row">
  <div class="col-md-11">
    <div class="box box-primary">
      <div class="box-header"></div>
        <div class="box-body">
          <form method="post">

            <table id="example" class="display" width="100%" cellspacing="0">
              <thead>
                <tr>
                   <td>
                     <select class="group_id" name="group_id[]" onchange="getcon();" multiple>
                       <option disabled selected>Select Group</option>
                       <?php
                          $select = "SELECT group_id,group_name
                                      FROM `group`";
                          $res1 = mysql_query($select);
                          while($group1 = mysql_fetch_array($res1))
                          {
                            echo '<option value='.$group1['group_id'].'>'.$group1['group_name'].'</option>';
                          }
                       ?>
                     </select>
                   </td>
                 </tr>
                  <tr>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>User Name</th>
                    <th>Password</th>
                    <th>First Name</th>
                    <th>Middle Name</th>
                    <th>Last Name</th>
                  </tr>
                   <tbody>
                      <tr>
                          <div class="group"></div>
                      </tr>
                   </tbody>
              </thead>
            </table>
        </div>
      </div>
    </div>
</aside><!-- /.right-side -->
</div><!-- ./wrapper -->

1 个答案:

答案 0 :(得分:0)

尝试添加此行

$("#example").dataTable().fnDestroy();
var table= $('#example').DataTable({"order": []});

$('.group').html(data);

这将重新加载数据表