Reputation: 5525
I need to have autocomplete feature on my website, but I'm not JSON-guy. I never dealing with JSON so I hope I still can have autocomplete from plain MySQL result.
but from what I saw here : http://jqueryui.com/demos/autocomplete/ I don't see any possibilities to get autocomplete from MySQL result. is it true?
Upvotes: 0
Views: 948
Reputation: 541
You just need to make an AJAX call and take the search results then send them back as JSON to the client side.Then just bind it with the AutoComplete Textbox.
The jQuery plgin to be used is http://docs.jquery.com/UI/API/1.8/Autocomplete
Example- A textbox with ID 'txtlocation' is added with autocomplete functionality here.
$(document).ready(function(){
$("#txtlocation").autocomplete({
source: function (request, response) {
$.ajax({
url: "/PublicHome/AutoPopulateLocation", //Call to Server Side
data: "{ 'searchText': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data, function (item) {
return {
value: item.Suburb
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});
},
open: function (event, ui) {
$(this).autocomplete("widget").css({
"width": 344,
"font-size": 11,
"font-family": "Arial"
});
}
});
});
Upvotes: 0