我發現了一篇關於jqueryui自動完成從here完成的不錯的文章。它演示瞭如何使用json從mysql獲取數據。它的工作完美。但我必須發送一個像下面這樣的變量值。傳遞額外的變量jqueryui自動完成
的index.php
<form>
<select name="typeo" id="typeo" class="select" title="Select Country from List">
<option>None</option>
<option>US</option>
<option>UK</option>
</select>
<input type="text" id="state" name="state" /> <input readonly="readonly" type="text" id="abbrev" name="abbrev" maxlength="2" size="2"/></p>
<input type="submit" name="submit" value="Submit" /></p>
而且jQuery的是
$('#abbrev').val("");
$("#state").autocomplete({
source: "states.php",
minLength: 2,
select: function(event, ui) {
$('#state_id').val(ui.item.id);
$('#abbrev').val(ui.item.abbrev);
}
});
});
現在我想給類型0的值states.php所以MySQL查詢可能就像
"SELECT statename, statecode FROM states where country='$typeoValue' AND statename LIKE '%$states%'"
那麼我該如何發送typeo的值呢?請任何人幫助我。 謝謝。
感謝@Dogbert的回答你幾乎寫的,但我已經到了一個小的修改狀源:功能(rqeuest){ ($ .getJSON( 「states.php」,{項:rqeuest.term,COUNTRYNAME :$(「#typeo」)。val()})); }現在數據出現在螢火蟲的控制檯上,但不要顯示下拉菜單的原因。你可以幫我嗎? – DAKSH