title: j_security_check with ajax
body: <p>EDIT: url is culprit I think. In working login.html case I got in log:</p>
  
  <p>FINE: Security checking request POST /SesamaMaven/protected/admin/j_security_check</p>
  
  <p>And in AJAX-version I got:</p>
  
  <p>FINE: Security checking request POST /SesamaMaven/</p>
  
  <p>I configured authentication in Glassfish with JDBCRealm and it seems to be working with normal login.html like that:</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;title&gt;Login Form&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form method="post" action="j_security_check"&gt;
  &lt;p&gt;You need to log in to access protected information.&lt;/p&gt;
  &lt;table&gt;
  &lt;tr&gt;
    &lt;td&gt;User name:&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="j_username" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Password:&lt;/td&gt;
    &lt;td&gt;&lt;input type="password" name="j_password" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;p&gt;&lt;input type="submit" value="Login" /&gt;&lt;/p&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My problem is that when I try to implement same with AJAX, it is not working. Is there any possibility to get that working?</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;form class="navbar-form pull-right"&gt;
      &lt;input class="span2" type="text" placeholder="Email" name="j_username" id="username"&gt;
      &lt;input class="span2" type="password" placeholder="Password" name="j_password" id="password"&gt;
      &lt;button type="button" class="btn" id="btnSignIn"&gt;Sign in&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code> $('#btnSignIn').click(function() {
  
  
  $.ajax({
                  type: "POST",
                  contentType: "application/text",
                  url: "j_security_check",
                  // This is the type what you are waiting back from the server
                  dataType: "text",
                  async: false,
                  crossDomain: false,
                  data: {
                      j_username: "admin",
                      j_password: "paSSWORD"
                  },
                  success: function(data, textStatus, xhr) {
                      alert('Thanks for your signin in! ' + xhr.status);
                      window.location = "/SesamaMaven/protected/adminWelcome.html";
                  },
                  error: function(jqXHR, textStatus, errorThrown) {
                      console.log(textStatus, errorThrown);
                      window.location = "/SesamaMaven/index.html";
                      alert(' Error in signIn-process!! ' + textStatus);
                  }
  
  
              });
          });
  </code></pre>
  
  <p><strong>QUESTIONS</strong></p>
  
  <p>1) What is the correct contentType: "application/text"?</p>
  
  <p>2) Is the URL tag correct one or should I use action?</p>
  
  <p>3) How about parameters username and password in case like that?</p>
  
  <p>Glassfish tries to authenticate but there is no user and password.</p>