Guest User

Untitled

a guest
Aug 17th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. function validateLoginForm() {
  2.  
  3. var url = "<%=(request.getContextPath())%>/Login.do";
  4. var username = document.getElementById("username").value;
  5. var password = document.getElementById("password").value;
  6. var params = { "username":username,
  7. "password":password
  8. };
  9.  
  10. var http = new XMLHttpRequest();
  11. http.open("POST", url, false);
  12. http.setRequestHeader("X-Requested-With","XMLHttpRequest");
  13. http.setRequestHeader("Content-type", "application/json");
  14. http.onreadystatechange = function() {
  15. if (this.readyState == 4 && this.status == 200) {
  16. $("html").html(this.responseText);
  17. }
  18. };
  19. http.send(JSON.stringify(params));
  20. return true;
  21. }
  22.  
  23.  
  24. <form name="loginForm" method="POST" autocomplete="off" onsubmit="return validateLoginForm()">
  25. ....
  26. ....
  27. ....
  28.  
  29. <tr id="userNameRow">
  30. <th id="usernameLabel">Username</th>
  31. <td align="left"><input name="username" id="username" autocomplete="off" type="text" aria-describedby="loginError"></td>
  32. </tr>
  33. <tr id="userPwdRow">
  34. <th id="passwordLabel">Password</th>
  35. <td align="left"><input name="password" id="password" autocomplete="off" type="password"></td>
  36. </tr>
  37.  
  38. JSONObject jsonObj = new JSONObject(requestBody);
  39. String username = (String) jsonObj.get("username");
  40. String password = (String) jsonObj.get("password");
Add Comment
Please, Sign In to add comment