Wait till user finish typing

Wait till user finish typing

Hi,


Am trying to get some data from DB , here am checking whether username is registered or not , if he register am getting some data related to that user and displaying on window .

I want function to wait for  untill user finish typing his username , 
then run the function , Below is my code ,


  1. $(function (){  
  2.         var minlength = 2;                        
  3.         $("#username").keyup(function () {
  4.         var that = this,
  5.         value = $(this).val();          
  6.         if (value.length >= minlength ) {
  7.                 $.ajax({                
  8.                         type: "GET",
  9.                         url: "Path_to_php",
  10.                         data: {'username' : value},
  11.                         dataType: "html",
  12.                         success: function(data){
  13.                                 if (value==$(that).val()) {
  14.                                         $("#content").append("<p>" + data + "</p>");
  15.                                 }
  16.                                 else {
  17.                                         alert ("Username Not Registered");
  18.                                 }
  19.                         }
  20.                 });
  21.                 }
  22.         });
  23. });

Here , when user start entering his name , that time only Function getting call for each char he entered 


Please Help        

Thank You
Pervez