title: Jetty servlet response to Ajax always empty
body: <p>Hi I try to run a java server on Jetty which should respond to an ajax call. Unfortunately the response seems to be empty when I call it with ajax. When I call <a href="http://localhost:8081/?id=something" rel="nofollow noreferrer">http://localhost:8081/?id=something</a> I get an answer.</p>
  
  <p>The Java Server:</p>
  
  <pre><code>   public class Answer extends AbstractHandler
  {
      public void handle(String target,
                         Request baseRequest,
                         HttpServletRequest request,
                         HttpServletResponse response) 
          throws IOException, ServletException
      {
          String id = request.getParameter("id");
          response.setContentType("text/xml");
          response.setHeader("Cache-Control", "no-cache");
  
          response.setContentLength(19+id.length());
          response.setStatus(HttpServletResponse.SC_OK);
          response.getWriter().write("&lt;message&gt;"+id+"&lt;/message&gt;");
          //response.setContentType("text/html;charset=utf-8");
  
          response.flushBuffer();
          baseRequest.setHandled(true);
      }
  
      public static void main(String[] args) throws Exception
      {
          Server server = new Server(8081);
          server.setHandler(new Answer());
  
          server.start();
          server.join();
      }
  }
  </code></pre>
  
  <p>The js and html:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  var req;
  
  function validate() {
     var idField = document.getElementById("userid");
     var url = "validate?id=" + encodeURIComponent(idField.value);
     if (typeof XMLHttpRequest != "undefined") {
         req = new XMLHttpRequest();
     } else if (window.ActiveXObject) {
         req = new ActiveXObject("Microsoft.XMLHTTP");
     }
     req.open("GET", "http://localhost:8081?id=fd", true);
     req.onreadystatechange = callback;
     req.send(null);
  }
  
  
  function callback() {
      if (req.readyState == 4) {
          if (req.status == 200) {
               var message = req.responseXML.getElementsByTagName("message")[0];
               document.getElementById("userid").innerHTML = "message.childNodes[0].nodeValue";
          }
      }
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="validate('foobar')"&gt;
  &lt;div id="userid"&gt;hannak&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'm actually don't know what I'm doing wrong here. Maybe someone has a good idea.</p>
  
  <p>greetings chris</p>