title: logout using AJAX and Java not working
body: <p>I have AJAX using jQuery which gets triggered when I click a link with the ID <code>logOut</code>.</p>
  
  <p>AJAX:</p>
  
  <pre><code>$("#logOut").click(function(){
    $.ajax({ 
      url: "Logout"
    });
  });
  </code></pre>
  
  <p>The AJAX calls my Java Servlet, see below:</p>
  
  <pre><code>/**
   * Servlet implementation class Logout
   */
  @WebServlet(description = "Logout User", urlPatterns = { "/Logout" })
  public class Logout extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#HttpServlet()
       *//*
      public Logout() {
          super();
          // TODO Auto-generated constructor stub
      }*/
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          HttpSession session = request.getSession();
          session.invalidate();
          response.setStatus(response.SC_MOVED_TEMPORARILY);
          response.setHeader("Location", "index.jsp#login");
      }
  
  }
  </code></pre>
  
  <p>When the link is clicked my jQuery always triggers however it does not always seem to call the logout Java Servlet. Why is this happening?</p>
  
  <p>EDIT:</p>
  
  <p>When I step through the jQuery code using Chrome dev tools it works but not when it's ran normally.</p>
  
  <p>HTML:</p>
  
  <p><code>&lt;li&gt;&lt;a class="linkButtons" href="" id="logOut"&gt;Log Out&lt;/a&gt;&lt;/li&gt;</code></p>