Render a list once it is avaialable

Render a list once it is avaialable

Hi ,
I am trying to make simple JQuery application with Auto complete .
I need when the user types each character --> go to server and do some logic there -->then render a list from the server .

I succeeded to do that .However, the only thing that BUGS me that once the response comes from the server , I must type another character in order to be able to render the list .

How could I render the list whenever it comes from the server without the need to type any thing .




  1. $(document).ready(function() { 


  2.        $('#autocomplete').keydown(function() {
  3. if ($('#autocomplete').val()) {

  4. $.getJSON("../x/foo", { name: $('#autocomplete').val()}, function(result) {

  5.                           $("input#autocomplete").autocomplete({source:result.fooList});
  6.                      });

  7. }
  8.   });

  9. });

  10. <input id="autocomplete"  />