我喜欢传销。所以我希望所有用户名都作为建议出现在父名称输入表单中。那么我该如何编写代码呢?包括哪个jquery?我添加以下代码
$query = isset($_GET[\'query\']) ? $_GET[\'query\'] : FALSE;
if ($query) {
// escape values passed to db to avoid sql-injection
$depts = $wpdb->get_results( "SELECT * FROM wp_mlm_info WHERE user_name LIKE \'".$query."%\' ORDER BY user_id ASC" );
$suggestions = array();
$data = array();
foreach($depts as $row) {
$suggestions[] = $row->user_name;
$data[] = $row->user_id;
}
$response = array(
\'query\' => $query,
\'suggestions\' => $suggestions,
\'data\' => $data,
);
echo json_encode($response);
添加以下jquery
wp_enqueue_script(\'newscript\',plugins_url( \'js/jquery-1.10.2.js\' , __FILE__ ),array( \'jquery\' ));
wp_enqueue_script(\'newscript\',plugins_url( \'js/jquery-ui.js\' , __FILE__ ),array( \'jquery\' ));
wp_enqueue_script(\'newscript\',plugins_url( \'js/jquery.min.js\' , __FILE__ ),array( \'jquery\' ));
wp_enqueue_script(\'newscript\',plugins_url( \'https://www.devbridge.com/projects/autocomplete/jquery/local/scripts/jquery.autocomplete.js/\' , __FILE__ ),array( \'jquery\' ));
但不能使用自动搜索或自动建议字段。
Javascript
$(document).ready(function(){
$(\'#parent_name\').autocomplete({
serviceUrl:\'/\',
// callback function:
onSelect: function(value, data){ alert(\'You selected: \' + value + \', \' + data); },
});
});
你能帮我解决这个问题吗?