christ_tp
christ_tp

Reputation: 13

Ajax Don't Show Search Value From DB

I've tried to show my search data using Ajax, but it doesn't work when I check in my console there is no error, first I get error from my references url but I've fixed but when I try to search the data but the data that I search doesn't show at all. Here is my code

<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>

This one from my "cari.php" :

<!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>

Thank's for your time.

Upvotes: 0

Views: 34

Answers (1)

Dinesh undefined
Dinesh undefined

Reputation: 5546

Your jquery selector is wrong. You should use # in selector for 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>

Upvotes: 1

Related Questions