title: Ajax request for login not working using $.post() method in jquery
body: <p>I have a login form i want to send username password to servlet and returning response from there but my username and password is not even going to servlet i have searched a lot but not getting anything please help me out ..
  my code is given belo :</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function () {
      $(".mloginform").submit(function () {
          var uName = $("#usernameInputField").val();
          var passwd = $("#passwordInputField").val();
  
          $.post("/LoginServlet", {
              username: uName,
              password: passwd
          }, function (data) {
              if (data.success) {
                  alert("hello");
              }
          }, 'json');
  
          return false;
      });
  });     
  &lt;/script&gt;
  </code></pre>
  
  <p>Inside LoginServlet doPost method:</p>
  
  <pre><code>String userName=request.getParameter("username");
  String passwd=request.getParameter("password");
  
  Gson gSon=new Gson();
  
  Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
  
  data.put("success", true);
  
  JsonObject myJson=new JsonObject();
  myJson.add("data", gSon.toJsonTree(data));
  response.setContentType("application/json");
  PrintWriter out = response.getWriter();
  out.write(myJson.toString());
  </code></pre>
  
  <p><strong>where I am wrong.</strong></p>