我正在尝试在自动完成功能中使用jQuery Ajax函数。自动完成功能正常,因为它返回值,但是当我选择一个值时,它不会执行任何操作。我想返回html并在div中显示。
jQuery的:
$(function() {
$("#store").autocomplete({
source: "includes/ajax/storenumbers.php",
select: function(event, ui) {
var storeid = val(ui.item.id);
$.ajax({
url: "includes/ajax/storecontacts.php",
type: "GET",
data: {term : storeid},
dataType: "html",
success: function(msg){
//Display html
$("#resultsdiv").html(msg);
},
error: function (request, status, error) {
alert(request.responseText);
}
});
}
});
});
HTML:
<form action="<?php echo $PHP_SELF;?>" method="post">
<label for="store">Enter Store #: </label>
<input type="text" id="store" name="state" />
<div id="resultsdiv" style="width: 200px; height: 200px;">
</div>
</form>
storenumbers.php返回“1”:
[{"id":"6","value":"10211","abbrev":"Concord"},{"id":"4","value":"10869","abbrev":"Maplewood"},{"id":"5","value":"16289","abbrev":"Hugo"},{"id":"12","value":"19245","abbrev":"WBL 4th Street"}]
storecontacts.php返回:
Name: Alex E-mail: alex@email.com View Order: yes Print Order: yes<br>
Name: Brooke E-mail: brooke@email.com View Order: no Print Order: no
我希望html返回最终是一系列输入文本字段和复选框。 dataType:html 仅限于某些内容吗?
答案 0 :(得分:0)
我明白了。我不得不将var storeid = val(ui.item.id)更改为var storeid = ui.item.id;