weixin_33713707 2016-05-06 14:03 采纳率: 0%
浏览 21

使用ajax或php刷新div

i am using a function to show and hide div and it's working fine , in one of these divs there is a table , i have a function (php) to search and filter the table and it's a;so working but the problem is when i press the search button(submit in php) the page refreshes (admin.php) showing the first (#pending) . Can i do the php function and stay in the same div(#users without the page refreshing to the begenning. These are the function that i am using:

1-hide and show:

    $(function(){
     $('#1').on('click',function(){
         $('#pending').show();
      $('#users').hide();
      $('#books').hide();
      $('#uploadbook').hide();
    });
    $('#2').on('click',function(){
      $('#users').show();
      $('#books').hide();
      $('#uploadbook').hide();
      $('#pending').hide();
    });
     $('#3').on('click',function(){
      $('#users').hide();
      $('#books').show();
      $('#uploadbook').hide();
      $('#pending').hide();
    });
     $('#4').on('click',function(){
      $('#users').hide();
      $('#books').hide();
      $('#uploadbook').show();
      $('#pending').hide();
    });


});

2- refresh div button:

$(document).ready(function(){
 $("#search").click(function(){
  $("#users").load("/s/admin.php");
 });
});

3-search(php):

<?php 
require_once 'connection.php';

 session_start();

 if(isset($_POST['search']))
{
    $valueToSearch = $_POST['valueToSearch'];
    // search in all table columns
    // using concat mysql function
    $query = "SELECT * FROM `r` WHERE CONCAT(`id`, `username`,`email`) LIKE '%".$valueToSearch."%'";
    $search_result = filterTable($query);

}
 else {
    $query = "SELECT * FROM `r`";
    $search_result = filterTable($query);
}

// function to connect and execute the query
function filterTable($query)
{
    $connect = mysqli_connect("localhost", "root", "", "x");
    $filter_Result = mysqli_query($connect, $query);
    return $filter_Result;
}
?>

I just want to stay where i am after the function is done , and i hope these details are enough for anyone to help me. Thank you.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向