title: Adding delay to a $.post jquery request
body: <p>I'm sending a jquery $.post request on any checkbox change in a form.
  What I want is to delay the $.post for 500 ms in case a user checks more than one checkbox rapidly, to avoid multiple useless requests.</p>
  
  <p>Here's my code, I've added a setTimeout function that seems to work with everything except this $.post function...</p>
  
  <pre><code>var delay = (function(){
    var timer = 0;
    return function(callback, ms){
      clearTimeout (timer);
      timer = setTimeout(callback, ms);
    };
  })();
  
  $(document).ready(function() {  
  
      $('.checkbox').change(function() {
  
          delay(function(){                             
              $.post("/?page_id=4", $("#selectors").serialize(), function(data){
                  $('#results').html(data);
              }); 
          });
  
      }, 1000 );
  
  });
  </code></pre>
  
  <p>Any idea why this doesn't work?</p>