having weird troubles with jQuery Autocomplete --
Hello friends.
Let me describe what this is about and what i've done so far.
As expected, I have a text box where the user would type in names of cities. And it is supposed to show an autosuggest/autocomplete prompt of city names that may match with the letters being typed. I have my server side code returning these city names.
1. my html is simple and such --
Search by City:
<input type="text" placeholder="type city name here ..." id="reg_city" style="border-radius: 6px;color: #21022c; background-color: #f8e7da; width: 310px; height: 38px;" />
2. the jquery code I did --
- $(document).on('keyups', '#reg_city', function () {
- $(this).autocomplete({
- source:function( request, response )
- {
- if(request.term!="")
- {
- $.ajax({
- type: 'POST',
- url: '@Url.Action("Get_CityAutocomp", "Home")',
- dataType: 'json',
- contentType: 'application/json; charset=utf-8',
- data:{name:request.term},
- success:function(serv_data)
- {
- if(serv_data!="")
- {
- response($.map(serv_data, function(item)
- {
- var name = item.name;
- return
- {
- label:name,
- value:name, <----------
- item:serv_data <----------
-
- };
- }));
- }
- }
- });
- }
- },
- autoFocus:true,
- minLength:2,
- delay:150,
- select:function(event, ui)
- {
- var name=ui.item.serv_data;
- $(this).val(name);
- }
- });
- });