我正在尝试让 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是否仅限于某些事情?