title: localStorage issue when doing ajax
body: <p>I have some simple code that will run to check Internet connectivity and I'm using <code>localStorage</code> to hold the variable value and yet when I run it the value of that variable isn't effected. So, what can I do to fix it. Please help. If the state is changed to <code>true</code> the submit will happen else otherwise it will be prevented.</p>
  
  <pre><code>localStorage.setItem("state","");
  
  function checkConnection(){             
     $.ajax({
         url:"assets/ping.js",
         success:function(res){
              localStorage.setItem("state","true");
         },
         onerror:function(){
              localStorage.setItem("state","false");
         } 
     });
   }
  
  $("form").submit(function(e){
  
     checkConnection();
  
     if(localStorage.getItem("state") == "false"){
          return false;
     } else if(localStorage.getItem("state") == "true") {
          return true;
     }
  
  });
  </code></pre>