[英]JQuery autocomplete json parse error
我嘗試使用JQuery自動完成功能,但出現此錯誤:
Uncaught SyntaxError: Unexpected token < in JSON at position 2
我的代碼是這樣的,HTML:
<div id="fastSearchBox" class="fastSearchBox">
<span style="direction: rtl; float: right;">search</span>
<input id="fastSearchInput" type="text" style="width: 150px; margin-right: 10px;"></input>
</div>
JavaScript:
users = [{"data":1,"value":"foo"}];
$("#fastSearchInput").autocomplete({
source: users,
select: function (event, ui)
{
}});
我不知道為什么,但是將source
更改為lookup
使其有效
具有標簽和值屬性的對象數組:[{標簽:“ Choice1”,值:“ value1”},...]
自動完成功能期望使用上述格式的數組。 將數組更改為以下內容:
<body>
<div id="fastSearchBox" class="fastSearchBox">
<span style="direction: rtl; float: right;">search</span>
<input id="fastSearchInput" type="text" style="width: 150px; margin-right: 10px;">
</div>
</body>
var users = [
{data: 1, value: "foo" },
{data: 2, value: "foo2" },
{data: 3, value: "foo3" }
];
$( "#fastSearchInput").autocomplete({
source: users
});
$( "#fastSearchInput").on( "autocompleteselect", function( event, ui ) {
alert(ui.item.data);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.