Ajax Don不显示来自数据库的搜索值

时间:2017-06-17 14:01:31

标签: php jquery ajax

我尝试使用Ajax显示我的搜索数据,但是当我在我的控制台中检查没有错误时它不起作用,首先我从我的引用网址中收到错误但是我已经固定,但当我尝试搜索数据但我搜索的数据根本没有显示。这是我的代码



<script type="text/javascript">
  $(document).ready(function(){
    $('#cari2').click(function(){
        $('#table_div').text("");
        $('#info').text("");
          $.ajax({
              url: "cari.php",
              type: "get",
              data: {"cari": $("#cari").val()},
              success: function(data){
                $('table_div').html(data);
              },
              error : function(xhr, teksStatus, kesalahan){
                $('info').html('<br>Error</br>')

              }
          });
    });


  });
  </script>
&#13;
&#13;
&#13;

来自我的&#34; cari.php&#34; :

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>
<link href="../../css/show_sisByName.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form method="get">
<table>
  <?php

    if(isset($_GET['cari'])){
    $cari = trim($_GET['cari']);

  ?>
  <thead>
    <th>NAMA SISWA</th>
    <th>AKSI</th>
  </thead>
<tbody>
<?php
  include "db_connect.php";
  try{
        $kueri = $dt_bas->prepare("SELECT nm_dpn FROM siswa WHERE nm_dpn LIKE :cari");
      //  $kueri->bindParam(1, $cari);
        $kueri->execute(array(':cari' => '%'.$cari.'%'));
  }catch(PDOException $e){

  }
  while ($row = $kueri->fetch(PDO::FETCH_ASSOC)) {
?>
          <!--- Tabel Row Start ASC------------------>
  <tr>
    <td><?php echo $row["nm_dpn"];?></td>

    <td>
      <a href="#">Ubah<a/>
      <a href="#">Detail</a>
    </td>
  </tr>
<?php
  } //end of while cari
}     
?>
</tbody>
</table>
</form>
</body>
</html>
&#13;
&#13;
&#13;

感谢您的时间。

1 个答案:

答案 0 :(得分:1)

您的jquery选择器是错误的。您应该在选择器中使用#作为id。 $('#table_div').html(data);

<script type="text/javascript">
  $(document).ready(function(){
    $('#cari2').click(function(){
        $('#table_div').text("");
        $('#info').text("");
          $.ajax({
              url: "cari.php",
              type: "get",
              data: {"cari": $("#cari").val()},
              success: function(data){
                $('#table_div').html(data);
              },
              error : function(xhr, teksStatus, kesalahan){
                $('info').html('<br>Error</br>')

              }
          });
    });


  });
  </script>
相关问题