0

hello everyone please help me to solve this problem . i make a search box for search user when i run the code nothing is show this is my all code

search.js

$(function(){
$('.search').keyup(function(){
    var search = $(this).val();
    $.post('http://localhost/tweet/core/ajax/search.php',{search:search},function(data){
        $('.search-result').html(data);
    });
});

});

search.php

<?php

  include '../init.php';

  if(isset($_POST['search']) && !empty($_POST['search'])){
$search = $getFromU->checkinput($_POST['search']);
$result = $getFromU->search($search);


echo ' <div class="nav-right-down-wrap">
<ul> ';
foreach ($result as $user) {
    echo '<li>
    <div class="nav-right-down-inner">
        <div class="nav-right-down-left">
            <a href="'.BASE_URL.$user->uname.'"><img src="'.BASE_URL.$user->Pimg.'"></a>
        </div>
        <div class="nav-right-down-right">
            <div class="nav-right-down-right-headline">
                <a href="'.BASE_URL.$user->uname.'">'.$user->screnname.'</a><span>@'.$user->uname.'</span>
            </div>
            <div class="nav-right-down-right-body">

            </div>
        </div>
    </div> 
 </li> ';
}

echo '</ul></div>';

}
?>

user.php

public function search($search){
    $stmt = $this->pdo->prepare("SELECT 'uid', 'uname', 'screnname' ,'Pimg', 'cimg' FROM 'users' WHERE 'uname' LIKE ? OR 'screnname' LIKE ?");
    $stmt->bindValue(1, $search.'%', PDO::PARAM_STR);
    $stmt->bindValue(2, $search.'%', PDO::PARAM_STR);
    $stmt->execute();
    return $stmt->fetchAll(PDO::FETCH_OBJ);
}

home.php

<li>
                <input type="text" placeholder="Search" class="search"/>
                <i class="fa fa-search" aria-hidden="true"></i>
                <div class="search-result">         
                </div>
            </li>

<script type="text/javascript" src="assets/js/search.js"></script>

Anyine please help me to solve this problem.Thanks

  • Is your `keyup` being called? (add a `console.log` to that function). What is the server responding with? (Check the `network` tab of the browser's dev-console). Are you getting any error messages? (I think it's `$pdo->errorInfo()`, for that portion of things) – Reed Apr 14 '20 at 20:08
  • i do that but nothing to show – Jerry's Streaming Apr 14 '20 at 20:16
  • Does your PHP server print errors? `ini_set('display_errors', 1); error_reporting(E_ALL);`? Or have error logs you can view? What happens if you go to `http://localhost/tweet/core/ajax/search.php` directly, instead of using the jquery? And then what if you pass paramaters as well? Add `?search=cats` & then set `$_POST=$_GET` (just for testing) at the top of your PHP script. – Reed Apr 14 '20 at 20:22
  • can't show anything – Jerry's Streaming Apr 14 '20 at 20:39
  • If you go to `http://localhost/tweet/core/ajax/search.php` & right click -> View source, there's nothing at all? What if you modify the PHP script to just `echo "cats"; exit;` @ the top (before the include)? (don't ask me why cats. It's just what I use lol). Wondering if your routing mechanism is even getting to your script. – Reed Apr 15 '20 at 15:54

0 Answers0