title: Best practice to initialize ajax request
body: <p>I have an ajax call wrapped into a function in order to do polling which is</p>
  
  <pre><code>function doPoll(){
          alert('GO POLL')
          setTimeout(function(){
              $.ajax({
                  'method':'POST',
                  'url':'/ajax/request_news',
                  'beforeSend':function(){
                      alert('Before send')
                      date = new Date()
                      var timestamp_last_check = Math.floor(date.getTime()/1000)
                  },
                  'data':{'last_check':timestamp_last_check}, 
                  'success':function(ret){
                      ret = $.parseJSON(ret)
                  },
                  'complete':function(){
                      doPoll()
                  }
  
              })
         },5000)
      };
  </code></pre>
  
  <p>This request doesn't work because it says that the var timestamp_last_check is not initialized. I though that putting this in <code>beforeSend</code> would work but it seems that the data context is retrieved before the <code>beforeSend</code> call. </p>
  
  <p>I can't put my timestamp initialization outside the AJAX call because there's the <code>setTimeout</code> who will cause a 5 seconds delay between the initialization of the timestamp and the AJAX call.</p>
  
  <p>I saw that there's a <code>$.ajaxSetup</code> function but the doc recommend not to use it.</p>
  
  <p>What's the best practice to initialize this <code>timestamp_last_check</code> var ? </p>
  
  <p>Thanks ! </p>