Clearing timeout for ajax query - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:ajax

Description

Clearing timeout for ajax query

Demo Code

ResultView the demo in separate window


<html>
 <head> 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script> 
 </head> //from   w  w  w.j a  v a2  s  .  co m
 <body> 
  <input id="search"> 
  <script>
function debounce(el)
{
  var exec;
  $(el).keyup(
  function ( )
    {
        if (exec)
        {
            clearTimeout(exec);
        }
        exec = setTimeout(function ()
        {
           console.log('1');
        }, 3000);
    });
}
debounce($("#search"));

      </script>  
 </body>
</html>

Related Tutorials