2017-07-06 50 views
0

jquery UIオートコンプリートを使用してスクリプトを作成していましたが、動作していないようですので、 here is his answer先読みデータがテキストボックスに表示されず、ネットワークタブに結果が表示されない

:私はライブラリを(私は bootstrap 4を使用していますので、私はそれのため typeaheadjs.cssライブラリをダウンロードした)を加え

$cid = $_SESSION['clinic_id']; 

$searchTxt = '%'.$_REQUEST['term'].'%'; 
$res = array(); 
$getPatients = "SELECT * FROM patient WHERE clinic_id = :cid and patient_name_en LIKE :searchTxt OR dob LIKE :searchTxt OR patient_id LIKE :searchTxt OR patient_phone LIKE :searchTxt OR unhcr_registration_number LIKE :searchTxt ORDER BY patient_id DESC"; 

$execGetPatients = $conn->prepare($getPatients); 
$execGetPatients->bindValue(':cid', $cid); 
$execGetPatients->bindValue(':searchTxt', $searchTxt); 
$execGetPatients->execute(); 
$getPatientsResult = $execGetPatients->fetchAll(); 

$i = 0; 
foreach($getPatientsResult as $result) 
{ 
    $res[$i] = $result; 
    $i++; 
} 

echo json_encode($res); 

<script> 
$(function() { 
    $("#searchTxt").typeahead({ 
    source: function(query, process) { 
     var textVal=$("#searchTxt").val(); 
     $.ajax({ 
     url: '/php/autoComplete.php', // Please add full URL here 
     type: 'POST', 
     data: 'term=' + textVal, 
     dataType: 'JSON', 
     async: true, 
     success: function(data) { 
      process(data); 
      console.log(textVal); 
     } 
     }); 
    } 
    }); 
}); 
</script> 

私はそれがあるようにそれを追加し、に私のPHPスクリプトを変更

<link rel="stylesheet" href="../css/bootstrap.min.css"> 
<link rel="stylesheet" href="../css/jquery-ui.css"> 
<link rel="stylesheet" href="../css/typeaheadjs.css"> 
<script src="../js/jquery-3.2.1.min.js"></script> 
<script src="../js/bootstrap.min.js"></script> 
<script src="../js/jquery-ui.js"></script> 
<script src="../js/typeahead.bundle.js"></script> 

ここでsearchTxtテキストボックスに入力すると、結果としてテキストボックスでもネットワークタブでも出力が表示されません。 (コンソールにエラーはありません)。

答えて

1

link

ドキュメントlink

デモ

[ 
    { 
    id: 1, 
    name: 'John' 
    }, 
    { 
    id: 2, 
    name: 'Alex' 
    }, 
    { 
    id: 3, 
    name: 'Terry' 
    } 
] 

以下Githuとしてデータの json形式を返す必要があり、このデモ#5

$('#demo5').typeahead({ 
    ajax: { 
      url: '/cities/list', 
      triggerLength: 1 
      } 
}); 

autocomplete.phpを参照してくださいb Link

希望します。

+0

動作しませんでした – droidnation

関連する問題