2013-05-07 63 views
-1

我有7個不同的選擇和2個文本框的搜索頁面。 存儲在選擇中的數據是從MYSQL數據庫中提取的。如何使用基於其他選擇的ajax更新我的HTML選擇?

現在當我做出選擇時,我希望其他選擇基於我所做的選擇進行更新。 這需要使用Ajax完成。有人能指引我朝着正確的方向嗎?

+4

這是一個非常廣泛的問題。有許多AJAX教程,您還可以查看相關側欄中的一些問題。 – Barmar 2013-05-07 09:03:11

回答

1

收集已經充滿選擇的值,並將其發送給服務器,以獲得過濾值列表。

假設您有汽車製造商/型號選擇器。

<select name="manufacturer"> 
<option value="1">Acura</option> 
<option value="2">Audi</option> 
... 
</select> 

<select name="model"></select> 

功能,以填補「模特」與價值選擇應該是這樣的:

$.get('/get_models_by_manufacturer', {manuf: $('select[name=manufacturer']).val()}, function(data){ 
    // data returned by the server is expected to be html code of options NOT surrounded with <select> 
    $('select[name=model]').html(data); 
}); 
相關問題