title: Handling AJAX error (Native JS)
body: <p>I am trying to handle AJAX error using below code but it is not working  </p>
  
  <pre><code>function ajaxPost(url, data, success, error) {
      var xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange = function () {
          if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status === 200) {
              if (typeof success === "function") {
                  success(xmlhttp.responseText);
              }
          }else if([404, 500 , 503, 504 ].indexOf(xmlhttp.status) &gt; -1){
              if(typeof error === "function"){
                  error();    
              }
          }
      }
      xmlhttp.open("POST", url, true);
      xmlhttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
      xmlhttp.send(JSON.stringify(data));
  }
  </code></pre>
  
  <p>Am I missing any other status code in <code>[404, 500 , 503, 504 ]</code>? I am not reinventing the wheel, I have programmed the whole DOM using native JavaScript and don't want to include 80KB file just for AJAX. Please help me on this. </p>
  
  <p>The above function is successfully posting the data to the server but failed to raise error when server is unavailable. Please help me to handle this.</p>