Ajax jQuery empty request

Ajax jQuery empty request

In my simple login page to send the login information to the servlet, and in response receives one parameter which is interpreted in jQuery.

Data is sent correctly, go to the servlet which also sets the parameter correctly what I see in firebug in response header.

The problem is when I want to download den parameter to a javascript variable. The request object is empty, while in chrome incpect see alert: Uncaught TypeError: Object has no method 'getResponseHeader'. When I display it using console.log () does not return anything to me, no value.


  • <!DOCTYPE html>
    1. <html lang="en">
    2. <head>
    3. <%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    4. <meta charset="utf-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta name="description" content="">
    7. <meta name="author" content="">
    8. <link rel="shortcut icon" href="../../assets/ico/favicon.png">
    9. <link
    10. href="http://minikomi.github.io/Bootstrap-Form-Builder/assets/css/lib/bootstrap.min.css"
    11. rel="stylesheet">
    12. <link
    13. href="http://minikomi.github.io/Bootstrap-Form-Builder/assets/css/lib/bootstrap-responsive.min.css"
    14. rel="stylesheet">
    15. <link
    16. href="http://minikomi.github.io/Bootstrap-Form-Builder/assets/css/custom.css"
    17. rel="stylesheet">
    18. <script src="http://code.jquery.com/jquery-2.0.3.js"></script>
    19. <script src="../js/jquery.validate.js"></script>


    20. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    21. <title>Logowanie</title>

    22. <!-- Bootstrap core CSS -->
    23. <link href="../css/bootstrap.min.css" rel="stylesheet">

    24. <!-- Custom styles for this template -->
    25. <link href="../css/signin.css" rel="stylesheet">

    26. <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    27. <!--[if lt IE 9]>
    28.       <script src="../../assets/js/html5shiv.js"></script>
    29.       <script src="../../assets/js/respond.min.js"></script>
    30.     <![endif]-->
    31. </head>

    32. <body>

    33. <div class="container">

    34. <form class="form-signin" action="Login" method="post">
    35. <h2 class="form-signin-heading">Logowanie</h2>
    36. <input type="email" name="email" class="form-control" id="email"
    37. placeholder="Adres email" autofocus>
    38. <input type="password" id="password"
    39. name="password" class="form-control" placeholder="Haslo">


    40. </form>
    41. <button id="zaloguj" value="zaloguj" class="btn btn-success btn-large">
    42. <i class="icon-white icon-th-list"></i>Zaloguj
    43. </button>

    44. </div>
    45. <!-- /container -->


    46. <!-- Bootstrap core JavaScript
    47.     ================================================== -->
    48. <!-- Placed at the end of the document so the pages load faster -->

    49. <script type="text/javascript">

    50. $('#zaloguj').click(function() {
    51. var email = $("#email").val();
    52. var password = $("#password").val();
    53. console.log(email+password);
    54. var data = "email=" + email + "&password=" + password;
    55. $.ajax({
    56. url : "Login",
    57. type : "POST",
    58. data : data,
    59. success : function(request) {
    60. console.log(request);
    61. var log = request.getResponseHeader("log");
    62. console.log(log);
    63. if (log == 1) {
    64. $( ":header" ).after("Poprawne logowanie").css({ background: "#ccc", color: "green" });
    65. document.location.href = '/landing.html';
    66. } else {
    67. $( ":header" ).after("Błędne logowanie").css({ background: "#ccc", color: "red" });
    68. }
    69. },

    70. });

    71. });
    72. </script>
    73. </body>
    74. </html>