I'm trying to populate auto suggestions with this javascript code but am unable to get it. I want to load data only if the first characters are matched to the entered data.
$(function() {
$("#city").autocomplete(
{
search: function () {},
source: function (request, response)
{
$.ajax(
{
url: 'getcities.php',
dataType: "json",
data:
{
term: request.term,
},
success: function (data)
{
response(data);
}
});
},
minLength: 2,
select: function (event, ui)
{
}
});
});
My json format is like this
[
{"id":"1","name":"Mumbai"},
{"id":"2","name":"Delhi"}
]