title: How to handle 204 response from ajax request in jquery
body: <p>I'm trying to handle a <code>Status: HTTP/1.1 204 No Content</code> error. I'm using <code>.fail()</code> to handle all other errors, but <code>204</code> is not handled by this function. While trying <code>if (jqXHR.status == "204") {alert("error!");}</code>, the alert is not thrown when a <code>204</code> is received.</p>
  
  <pre><code>$.ajax({
      url: url,
      method: 'GET',
      headers: {
          "Authorization": bearerToken
      },
  }).then(function(response) {
      var obj = response;
      $("#imageid").css("border-color", "#ccc");
      $(".search-results").empty();
      for (var property in obj.entity.entries) {
          if (obj.entity.entries.hasOwnProperty(property)) {
              $(".search-results").append($("&lt;li&gt;&lt;a href='" + obj.entity.entries[property].uri + "' target='_blank'&gt;&lt;div class='thumbnail'&gt;&lt;img width='30' height='30' src='" + obj.entity.entries[property].uri + "' target='_blank'/&gt;&lt;/img&gt;&lt;div class='caption'&gt;&lt;p&gt;" + obj.entity.entries[property].orientation + "&lt;/p&gt;&lt;/div&gt;&lt;/a&gt;&lt;/li&gt;"));
          }
      }
      //$(".search-results").append("&lt;div class='caption'&gt;" + data.id + "&lt;/div&gt;&lt;div class='thumbnail'&gt;&lt;img width='40' height='40' src='" + data.thumbnailUrl + "'/&gt;&lt;/img&gt;").css("float", "left");
  }).fail(function(data, jqXHR) {
      if (jqXHR.status == "204") {
          $(".search-results").empty();
          $(".search-results").append("&lt;p class='alert alert-danger'&gt;Invalid ID&lt;/p&gt;");
          $("#imageid").css("border-color", "red");
      }
      $(".search-results").empty();
      $(".search-results").append("&lt;p class='alert alert-danger'&gt;Invalid ID&lt;/p&gt;");
      $("#imageid").css("border-color", "red");
  });
  </code></pre>