I want to implement a search box in my website with autocompleting text together with the photo.
Here’s my current code:
HTML:
<h4>search:<input type="text" id="name-list" /></h4>
JavaScript:
$(function () {
$("#name-list").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Home/Searchuser",
type: "POST",
dataType: "json",
data: {
searchText: request.term,
maxResults: 10
},
success: function (data) {
response($.map(data, function (item) {
return {
label: item.DisplayName + " R:" + item.Reputation,
value: item.DisplayName,
id: item.Id
}
}))
}
})
},
select: function (event, ui) {
alert(ui.item ? ("You picked '" + ui.item.label + "' with an ID of " + ui.item.id) : "Nothing selected, input was " + this.value);
}
});
});
I’m using ASP.NET MVC2, and I’m passing the json string (after querying the local db) with image url and other information from the controller to the view. Text is working fine.
Can anybody help me how to render image and append to the list item?
I made these changes to the code and then it worked well.
CSS:
JavaScript: