title: Javascript Is it possible to check whether file is exist or not before Http Request?
body: <p>I use the simple AJAX and use google debug then find that the url is not exist...</p>
  
  <p>The code is very simple:</p>
  
  <pre><code>var http;
  
  if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
    http=new XMLHttpRequest();
  } else {
    http=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  try {
    http.open("GET", 'http://'+ip+':5000/test.html', true);
    http.onreadystatechange = onRcvData;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
      http.send(null);
    } else {// code for IE6, IE5
      http.send();
    }
  } catch(e) {
    http.abort();
  }
  
  function onRcvData() {
    if (http.readyState==4) {
      if (http.status==404) {
  
      } else if(http.status==200) {
  
      } else {
  
      }
    }
  }
  </code></pre>
  
  <p>It's okay if the file test.html exists.
  When the file isn't exist, the error show in the part:</p>
  
  <pre><code>if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
    http.send(null);
  } else { // code for IE6, IE5
    http.send();
  }
  </code></pre>
  
  <p>So, even if I use the onreadystatechange method cannot prevent the error...</p>
  
  <p>The file is in a directoy beside my web pages.</p>
  
  <p>Then what should I do to combine with httprequest?</p>
  
  <p>Any advice appreciate.</p>
  
  <p>Add:</p>
  
  <p>I have used the method 'Head' but it is return 404... (No matter jQuery plugin/javascript)</p>
  
  <p>Like the picture: 
  <img src="https://i.stack.imgur.com/Qtx5U.jpg" alt="enter image description here"></p>
  
  <p>What should I do...</p>
  
  <p>Is the direction of the error I found misleaded?</p>