title: intercept form submit with jQuery
body: <p>I want to intercept a submit via jQuery and first check if a file is present on the server. If it's present continue with the request, if not display a message and don't send the request. This is what I have:</p>
  
  <pre><code>$("#methodForm").submit(function(e){
  
      checkIndex('upload/segments.gen').done(function() {
          return true;
      }).fail(function () {
          e.preventDefault();
          alert("No index present!");
          return false;
      });
  });
  </code></pre>
  
  <p>this is the <code>checkIndex()</code>:</p>
  
  <pre><code>function checkIndex(file){
      return $.ajax({
          url : file,
          type:'HEAD'
      });
  }
  </code></pre>
  
  <p>What happens is this: The file is present on the server, but the <code>checkIndex</code> returns with fail. First I see the alert popup and then it continues and sends the post request to the server.</p>
  
  <p>I use the <code>checkIndex()</code> for other purposes as well where it works like expected so I'm pretty sure the error is somewhere in the submit routine. But I can't find out what's wrong with it.</p>