title: Using Ajax and jQuery to check if file exists - always returns 200 response
body: <p>So I'm need to check whether a file exists before showing specific data to clients...using jQuery I have this:</p>
  
  <pre><code>&lt;script&gt;
  function fileExists(fileLocation) {
      var response = $.ajax({
          url: fileLocation,
          type: 'HEAD',
          async: false
      }).status;
      alert(response);
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>When I attempt to run the function:</p>
  
  <pre><code>&lt;script&gt; fileExists('http://www.example.com/123.jpg'); &lt;/script&gt;
  </code></pre>
  
  <p>(where example.com is my domain), I ALWAYS receive a 200 response code.  I was wondering why this might be happening - could it be that I have a custom error page set through .htaccess?  Or, is there a better method to do this?</p>
  
  <p><strong>Note</strong>: jQuery 1.5.1 is being used.</p>
  
  <p><strong>Update</strong>: It seems it is being directed to our custom error page set through .htaccess:</p>
  
  <pre><code>ErrorDocument 404 http://www.example.com/errors/notfound.php
  </code></pre>
  
  <p>Not sure if this causes the conflict, or how to get around it.</p>
  
  <p><strong>SOLVED</strong></p>
  
  <p>I checked the headers for my custom 404 page, it was returning a 200 response code.  Had to hard code the header:</p>
  
  <pre><code>&lt;?php header('HTTP/1.1 404 Not Found'); ?&gt;
  </code></pre>
  
  <p>which would then return the 404 response code - fixing my issue.</p>