dongwen7187 2017-06-17 14:01
浏览 16

Ajax不显示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.

</div>
  • 写回答

1条回答 默认 最新

  • dongye9191 2017-06-17 14:13
    关注

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭