0

Ajax autocomplete response values are not coming to select option to display the text in the filed. Please advise how to get the value in select event.

$("#parts").autocomplete({
source: function(request, response) {
$.ajax({
url: "searchPart.jsp",
type: "POST",
dataType: "json",
data: { name: request.term},
success: function (data) {
        tempResults = data;
       response($.map(data, function (value, key) {
            return {
                label: key,
                value: key
            };
        }));
        }
      });
},
minLength: 3,
select: function (event, ui) {
 //event.preventDefault();
var name = tempResults[ui.item.value].value;
var id = tempResults[ui.item.value].key;

$('#partname').val(name);
$('#partname').text(name);
}  
}); 

</script>
</head>

<body>
<form>
<input type="text" name="part" id="parts" />
<input type="text" name="partname" id=partname/>
4

1 回答 1

1

您的select()事件处理程序在ajax()调用中,而不是autocomplete()调用中。如果您告诉您的编辑器修复您的缩进,那将是显而易见的。

于 2013-11-12T21:30:33.163 回答