Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript wordpress中ajax调用后未定义的wpdb_Javascript_Php_Ajax_Database_Wordpress - Fatal编程技术网

Javascript wordpress中ajax调用后未定义的wpdb

Javascript wordpress中ajax调用后未定义的wpdb,javascript,php,ajax,database,wordpress,Javascript,Php,Ajax,Database,Wordpress,我正在尝试使用ajax访问数据库,而无需重新加载页面。首先,从输入字段检索字符串 <div class="row input search"> <label>Findr</label> <input type="text" id="ppl" placeholder="Search.." autocomplete="off"> <div id="results"></div> </div> 我

我正在尝试使用ajax访问数据库,而无需重新加载页面。首先,从输入字段检索字符串

<div class="row input search">
     <label>Findr</label>
     <input type="text" id="ppl" placeholder="Search.." autocomplete="off">
<div id="results"></div>
</div>
我必须在search.php中使用$wpdb,但是我在syng中得到一个错误

对成员函数的调用在中获取非对象的\u结果


所以我认为$wpdb在search.php中是未定义的。我在官方的wordpress网站上读过一些例子,但不太清楚。有什么办法解决这个问题吗?

你能展示一下search.php中的代码吗?WP和Ajax需要……今天早上我喝的咖啡因不够@brasofilo是对的,WP有一种处理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;
}