0

I am trying to access a database without reloading the page by using ajax. First the string is retreived from the input field.

<div class="row input search">
     <label>Findr</label>
     <input type="text" id="ppl" placeholder="Search.." autocomplete="off">
<div id="results"></div>
</div>

And here is the ajax:

function search() {
var query_value = $('#ppl').val();
if(query_value.length >= '4'){
    $.ajax({
        type: "POST",
        url: "../search.php?search="+query_value,
        data: { query: query_value},
        cache: false,
        success: function(html){
            $("#results").html(html);
        }
    });
}return false;
}

And I have to use $wpdb in the search.php, but I get an error sying

Call to a member function get_results() on a non-object in...

So I figured that $wpdb is undefined in search.php. I've read some examples on the official wordpress site but it's not that clear. Any ideas how to fix this?

Paktwis Homayun
  • 300
  • 3
  • 17

0 Answers0