我在我的一個應用程序中使用Ajax Autocomplete for Jquery
(http://www.devbridge.com/projects/autocomplete/jquery/)。搜索表單看起來是這樣的:jQuery的Ajax自動完成:如何發送動態參數
<form id="topsearch" method="POST" action="/searchAll"><input type="text" class="searchform" name="q" id="q" value="Country, City, Hotel or a Tourist Attraction" o nfocus="clearInput(this);" onblur="defaultInput(this);" />
<select id="top_search_select" name="entity_type">
<option value="country">Countries</option>
<option value="city">Cities</option>
<option value="place" selected="selected">Tourist Attractions</option>
<option value="hotel">Hotels</option>
</select>
<input type="submit" name="topsearch" class="submit" value="SEARCH" title="SEARCH"/>
</form>
,並自動完成配置是這樣的:
<script type="text/javascript">
//<![CDATA[
var a = $('#q').autocomplete({
serviceUrl:'/search',
delimiter: /(,|;)\s*/, // regex or character
maxHeight:400,
width:325,
zIndex: 9999,
params: {entity_type:$('#top_search_select').val()},
deferRequestBy: 0, //miliseconds
noCache: false, //default is false, set to true to disable caching
onSelect: function(value, data){window.location.replace(data);},
});
//]]>
</script>
現在的問題是在後端我有一個生成不同類型的實體的結果不同的處理程序用戶將通過表格中的選擇選項進行選擇。
默認entity_type
是place
這是正好傳遞給後端的處理程序。然而,我想要的是,當一個人從腳本配置中的params: {entity_type:$('#top_search_select').val()}
形式的選擇框中選擇不同的實體時,也會得到更新。
任何幫助或想法將不勝感激。謝謝。
我試着使用你的解決方案,但無濟於事。傳遞動態參數需要做些什麼。 –
調用「setOptions」方法也許:/ – Amyth