title: Why isn't the ready state changing to 4?
body: <p>I made a simple form and on clicking submit it goes to AJAX and after processing it is sent to the servlet. I am not printing the servlet's response and just showing an alert, but its not working. Please, any solutions.
  JSP:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
              var x = new XMLHttpRequest();
              function fn1()
              {
                  x.onreadystatechange = fn2();
  
                  x.open("GET","servlet1",true);
                  x.send();
  
              }
  
              function fn2()
              {
                  alert("happy");
                  if(x.readyState==4)
                  {
                      alert("happyness");
                  }
              }
  
  
          &lt;/script&gt;
  </code></pre>
  
  <p>Servlet: </p>
  
  <pre><code>public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
  
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
  
      out.print("hello");
  }
  </code></pre>
  
  <p>Web-xml:</p>
  
  <pre><code>&lt;servlet&gt;
  &lt;description&gt;This is the description of my J2EE component&lt;/description&gt;
  &lt;display-name&gt;This is the display name of my J2EE component&lt;/display-name&gt;
  &lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;
  &lt;servlet-class&gt;ajaxeg2.servlet1&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;servlet1&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/servlet1&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>