I found error when using jQuery autocomplete.
This notice error in console is
TypeError: $(...).autocomplete(...).data(...) is undefined }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
Code:
Site Name <br/>
<input type="text" name="site_name" id="site_name"><br/>
<input type="hidden" name="site_id" id="site_id">
$().ready(function () {
$("#site_name").autocomplete({
source: function (request, response) {
$.ajax({
url: "get_site2.php",
dataType: "json",
data: {
term: request.term
},
beforeSend: function () { // add this
showLoading("remove");
console.log("remove");
},
success: function (data) {
response(data);
}
});
},
minLength: 2,
select: function (event, ui) {
$("#site_name").val(ui.item.label);
$("#site_id").val(ui.item.name);
return false;
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
}).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("ui-autocomplete-item", item)
.append("<a>" + item.label + "</a>")
.appendTo(ul);
};
});
I confused, I already search and try this question but it did not fix it.