Autocomplete not loading on keydown

Autocomplete not loading on keydown

I want to capture keydown event so i use .live() method and attach autocomplete plugin . But it seems using .live() doesn't trigger the autocomplete. The keydown event is captured i have used alert to confirm it.But autocomplete is not loading. When i use ready() function autocomplete loads when I use live() function autocomplete won't load. What im trying to do is every keydown on input field im calling ajax to get information from server side and populate it in autocomplete plugin.

This works: USING ready();
  1. $(document).ready(function() { 
       
        var value = "a";

            $.ajax({
            type : "GET",
            url  : "../view/getSuggetion.htm?value=" + value,
            cache: false,
            dataType: "json",
            success: function(data) {
                alert("success: "+ data);
                    var  countries = $.map(data, function (value) { return value; });
                    alert("countries: "+ countries);

                     // Initialize autocomplete with local lookup:
                    $('#autocomplete').autocomplete({
                        lookup: countries,
                        onSelect: function (suggestion) {
                            $('#selection').html('You selected: ' + suggestion.value + ', ' + suggestion.data);
                        }
                    });
           
              
                },
            error: function(data, textStatus, errorThrown) {
                    alert(data + '-' + textStatus + '-' + errorThrown + '');
            }
        });   

        }





























This doesn't work: USING live()
  1. $('#autocomplete').live('keydown', function(){
        var value = "a";

            $.ajax({
            type : "GET",
            url  : "../view/getSuggetion.htm?value=" + value,
            cache: false,
            dataType: "json",
            success: function(data) {
                alert("success: "+ data);
                    var  countries = $.map(data, function (value) { return value; });
                    alert("countries: "+ countries);

                     // Initialize autocomplete with local lookup:
                    $('#autocomplete').autocomplete({
                        lookup: countries,
                        onSelect: function (suggestion) {
                            $('#selection').html('You selected: ' + suggestion.value + ', ' + suggestion.data);
                        }
                    });
           
              
                },
            error: function(data, textStatus, errorThrown) {
                    alert(data + '-' + textStatus + '-' + errorThrown + '');
            }
        });
           
           
        } );





























Any help is appreciated. :D