Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The response body is available by <code>xhr.responseText</code>. </p> <p>However, the <a href="http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html#sendError%28int,%20java.lang.String%29" rel="noreferrer"><code>HttpServletResponse#sendError()</code></a> ( &lt;-- click the link to read the Javadoc yourself) will use the servletcontainer's default error page template or your custom error page template as you've definied in <code>web.xml</code>. This is a HTML document which you thus have to parse yourself. </p> <p>As per your comment on the other answer, you seem to be using Tomcat and retrieving its default error page; the message is available as first <code>&lt;u&gt;</code> element of the second <code>&lt;p&gt;</code>. So this should do:</p> <pre><code>var errorMessage = $(xhr.responseText).filter('p:eq(1)').find('u').text(); if (errorMessage == 'unavailableimage') { // ... } </code></pre> <p>You only need to keep in mind that you're this way tight coupled to the markup of the (default) error page. Better is to not use <code>HttpServletResponse#sendError()</code>, but just set the status by <a href="http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html#setStatus%28int%29" rel="noreferrer"><code>HttpServletResponse#setStatus()</code></a> ( &lt;-- yes, click it to read javadoc, the answer was in there) and write the error message to the response body yourself:</p> <pre><code>response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.getWriter().write("unavailableimage"); </code></pre> <p>This way the <code>xhr.responseText</code> is exactly <code>unavailableimage</code>.</p> <pre><code>if (xhr.responseText == 'unavailableimage') { // ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload