title: how to allow one method to be accessed by only refresh at a time in jquery
body: <p>i have one method which is called when ever i refresh my page and that method saves a value in the database.Now if i refresh the same page continuously 3-4 times then the value is stored 3-4 times in database. I want if i refresh it 3-4 times continuously then it should be called only the first time.</p>
  
  <pre class="lang-js prettyprint-override"><code>window.onbeforeunload = confirmClose;
  
  function confirmClose() {
    var refreshTime = new Date().getTime();
    if (!isNaN(keyerAudit.auditStartTime) &amp;&amp; (keyerAudit.auditStartTime != 0))
      sessionStorage.setItem("FIRSTVISIT", refreshTime);
    var refreshAuditTime = 0;
    if (!isNaN(keyerAudit.auditStartTime) &amp;&amp; (keyerAudit.auditStartTime != 0))
      refreshAuditTime = (refreshTime - keyerAudit.auditStartTime) / 1000.0;
    if (!isNaN(refreshAuditTime) &amp;&amp; (refreshAuditTime != 0)) {
      sessionStorage.setItem("DB", refreshAuditTime);
      $.ajax({
        url: '/auditTimecalculate',
        type: 'POST',
        async: false,
        dataType: "json",
        data: {
          auditTime: refreshAuditTime
        },
        success: function(data) {
          console.log("returned from /auditTimecalculate ");
          console.log("the before refresh starttime was: ", keyerAudit.auditStartTime);
          sessionStorage.setItem("FIRSTVISIT", keyerAudit.auditStartTime);
          //                 refreshTime=undefined;
          refreshAuditTime = undefined;
        }
      });
    }
  </code></pre>