title: XmlHttpRequest status=0
body: <p>I have this ajax call from a javascript file and I want to pass as a parameter the id of the user that I want to delete:</p>
  
  <pre><code>function eliminaUtente(id,nome){
  if (confirm("Sei sicuro di voler eliminare l'utente "
      + nome
      + "?")) {
  var xmlHttp2 = new XMLHttpRequest();
  xmlHttp2.open("POST", "EliminaUtente", true);
  xmlHttp2.setRequestHeader("Content-type",
          "application/x-www-form-urlencoded");
  var params2 = "id=" + id;
  xmlHttp2.send(params2);
  xmlHttp2.onreadystatechange = function() {
      if (xmlHttp2.readyState == 4) 
      {
                      alert(xmlHttp2.status);  &lt;-----------this prints always 0!
          if (xmlHttp2.status == 200) //
          {
              alert("utente eliminato!");
          } else {
              alert("An error occurred while communicating with server.");
          }
      }
  };
  </code></pre>
  
  <p>}
  }</p>
  
  <p>in the correspondant Servlet called EliminaUtente i have this code:</p>
  
  <pre><code>  protected void doPost(HttpServletRequest request,
          HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      String id = request.getParameter("id");
      System.out.println(id);
      String query = "delete from utente where idutente=" + id;
      System.out.println(query);
      try {
          Class.forName("com.mysql.jdbc.Driver").newInstance();
  
          Connection con = DriverManager
                  .getConnection("jdbc:mysql://localhost/Spinning?user=root");
          PreparedStatement prest = con.prepareStatement(query);
          prest.executeUpdate();
  
          response.setContentType("text/plain");
          PrintWriter ajaxWriter = response.getWriter();
          ajaxWriter.print("ok");
          ajaxWriter.flush();
          ajaxWriter.close();
  
          con.close();
      } catch (Exception e) {
          e.printStackTrace();
          response.setContentType("text/plain");
          PrintWriter ajaxWriter = response.getWriter();
          ajaxWriter.print("ko");
          ajaxWriter.flush();
          ajaxWriter.close();
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I can't understand where is the problem...can you help me please? ;)</p>