所以我使用這個jQuery插件: jSuggest
這是基於這個插件:autoSuggestjQuery插件不返回從AJAX的JSON返回的結果
下面是與jSuggest的(工作)演示一個的jsfiddle: demo
這是我使用的實例在我的網頁插件的代碼:
<form id="add" action="components/AddItem.php" method="post" enctype="multipart/form-data" class="center clear">
<fieldset>
<legend>Basic Information</legend>
<label for="name">Name</label>
<br />
<input type="text" name="name" id="name"/>
...[snip]...
</form>
。
$('#name').jSuggest({
source: "components/suggItem.php",
selectedItemProp: "name",
seekVal: "name",
selectionLimit: 1,
uniqID: "item",
keyDelay: 100,
newText: "You must click outside the text box to add a new item."
});
這是從"components/suggItem.php"
當我輸入 「CH」 到文本框中返回字符串:
[ {"value":"1","name":"Cheeseburger"},{"value":"3","name":"Fish Sandwich"} ]
(這是Content-type: application/json
,我從螢火得到它)
不過,我只有永遠得到的下拉列表是"No Results Found"
。任何人都可以在我的代碼中找到一個bug?
我也曾嘗試:
$('#name').jSuggest({
source: "components/suggItem.php",
seekVal: "name",
});
和"value"
和"name"
各種組合。
我不明白爲什麼這不起作用。任何幫助?
是什麼讓你選擇了特定的插件?我沒有看到它的ajax處理代碼可能可以正常工作。 – Pointy 2011-04-13 00:44:11
@Pointy我喜歡Drew Wilson的插件,這個插件修復了他的很多bug。我願意提供更好的建議......您的意思是哪個AJAX部分?它使用jQuery的getJSON,所以我認爲它非常穩定。 – rockerest 2011-04-13 00:45:07
它*誤用* getJSON - 您發佈的代碼似乎假定getJSON的結果將立即可用,這是錯誤的。您發佈的代碼看起來與可能來自插件主頁http:// scottreeddesign的代碼有很大不同。com/project/jsuggest – Pointy 2011-04-13 00:50:08