【发布时间】:2015-08-05 03:45:30
【问题描述】:
我想在 Wordpress 上使用 jQuery UI 自动完成功能,但由于某种原因它不起作用。
无论如何,我会告诉你我已经拥有的:
HTML
<input type="text" name="db-search" id="db-search" autocomplete="off" />
JavaScript
$('#db-search').autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
url:"/wp-content/themes/your-click/autocomplete.php",
data: { autocomplete: 'true' },
});
}
}, { minLength: 1 });
PHP (autocomplete.php)
<?php
global $wpdb;
$string = wpdb::_real_escape( $_GET['term'] );
$get_results = $wpdb->get_results("SELECT * FROM yc_customers WHERE website LIKE $string ORDER BY website ASC");
$json[] = '';
foreach ($get_results as $get_result) {
array_push($json, $get_result->website);
}
echo json_encode($json);
flush;
?>
在使用 chrome 进行测试时,我没有收到任何错误。所以我不知道我的代码有什么问题,但我猜 PHP 肯定有问题。
【问题讨论】:
标签: php jquery wordpress jquery-ui autocomplete