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

使用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条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 GEO下载数据的处理报错 :函数‘Meta’标签‘"data.frame"’找不到继承方法,如何解决?
      • ¥15 DLNM模型是否可以用二分类变量作为y变量
      • ¥15 android object box 一个实体多个表怎么写
      • ¥15 temux 启用docker 服务失败
      • ¥15 Flask 使用celery发送邮件出现‘目标计算机积极拒绝‘
      • ¥60 老人用的sd卡在手机里面不知道操作了什么,导致图片和视频变成了文件,取下sd卡连接电脑就是图中的样子,后缀改为.jpg才可以,需要用系统的画图软件才能打开,文件属性还是文件,有没有批量操作的解决办法
      • ¥15 超时跳出方法代码的返回值问题
      • ¥15 汇编语言程序设计设计,ascii码求数,再求数的BCD码
      • ¥30 Mask rcnn训练自己的数据集出现问题!
      • ¥20 研究人工智能时的几个问题