リモートデータソースのJQueryオートコンプリートに問題があります。私は入力が始まるたびにリクエストが行われているのを見ていますが、JQueryの出力は表示されません。誰でも助けることができますか? perfomrsリモートデータソースを使用したJQueryオートコンプリート
コード検索:
$term=$_GET['term'];
$query = "SELECT Items.ItemID, Items.ItemCode, Items.ItemDescription FROM
Items WHERE Items.ItemCode LIKE '%$term%' ";
$stmt = $db->prepare($query);
$stmt->execute();
$stmt->store_result();
$numrows = $stmt->num_rows;
$stmt->bind_result($ItemID, $ItemCode, $ItemDescription);
for ($i=0; $i <$numrows; $i++) {
$stmt->fetch();
$arr[] = array(
"value" => strval($ItemCode),
"label" => strval($ItemDescription)
);
}
header("Content-Type", "application/json");
echo json_encode($arr);
私は、次のJSON出力を得る:
[{"value":"1085","label":"Item1"},{"value":"2089","label":"Item2"}]
をI jQueryのための次のコードを持っている:divのための
<script>
$(function() {
function log(message) {
$("<div>").text(message).prependTo("#log");
$("#log").scrollTop(0);
}
$("#items").autocomplete({
source: function(request, response) {
$.ajax({
url: "../items-search.php",
dataType: "jsonp",
data: {
term: request.term
},
success: function(data) {
response(data);
}
});
},
minLength: 1,
select: function(event, ui) {
log("Selected Item: " + ui.item.value );
}
});
});
</script>
とHTMLを:
<div>
<label for="items">Item: </label>
<input id="items">
</div>
<div>
Result:
<div id="log"></div>
</div>
ありがとうございます。私はちょうどそれを変更した、 – Luke