【发布时间】:2017-05-24 14:58:22
【问题描述】:
我想在昵称搜索栏中添加自动完成功能。我不明白为什么它不起作用。我的代码正确吗?
在我的文件 liste.php 中
global $wpdb;
$name = $_POST['code_postal'];
$sql = $wpdb->get_results("SELECT * FROM membres WHERE pseudo LIKE '$name%' ");
$titles = array();
foreach($sql as $key=> $value){
echo $value->pseudo;
}
echo json_encode($titles); //encode into JSON format and output
在我的 global.js 中
$('#recherche').autocomplete({
source: function(name, response) {
$.ajax({
type: 'POST',
dataType: 'json',
url: 'wp-content/themes/ARLIANE/liste.php',
data: 'action=get_listing_names&name='+name,
success: function(data) {
response(data);
}
});
}
});
在我的 index.php 中
<form>
<input type="text" name="term" id="recherche"/>
</form>
【问题讨论】:
-
liste.php [...] 成员 [...] 中的错字?
-
对不起,我不明白...
-
我猜你想访问表“成员”,但正在尝试“成员”,这将是一个拼写错误
-
不,这是好的“成员”。我是法国人;)
标签: javascript php jquery wordpress jquery-ui