私はデータを取得するためにjsonを使用しています。
ここにphpコードがあります
sq=$wpdb->get_results($wpdb->prepare("SELECT * FROM wp_posts where post_type='post' and post_title LIKE '%{$q}%'"));
$array=配列();
foreach($sq as $fsq) {
$array[]=array( "id" => "$fsq->ID", "text" => "$fsq->post_title" );
}
echo json_encode($配列);
ここにJqueryがあります
jQuery('.searchh').typeahead({
source: function (query, process) {
jQuery.ajax({
url: 'wp-content/themes/wordpress-bootstrap-master/field2.php',
type: 'POST',
dataType: 'JSON',
data: 'query=' + query,
success: function (data) {
jQuery.each(data, function (index, data) {
console.log(data['text']);
process(data['text']);
});
}
},
minLength: 1,
items: 9999,
onselect: function (obj) { console.log(obj) }
})
データが正しくプルされている.つまり、json が正しく機能していることを意味します.唯一の競合は、先行入力コードとの競合です.データがプルアップされると、何も起こらず、コンソールログにエラーさえ表示されません.
私はそれに多くの時間を無駄にしました.Plz助けてください.