Advertisement
Guest User

Untitled

a guest
Mar 7th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  2. <script>
  3. $(document).ready(function(){
  4. $('#login').click(function(event){
  5. event.preventDefault();
  6.  
  7. var username = $("#username").val();
  8. var password = $("#password").val();
  9. var servlet = '${pageContext.request.contextPath}/LoginServlet';
  10. $.ajax({
  11. type: 'GET',
  12. url: servlet,
  13. data: {username: username, password: password},
  14. success: function(data) {
  15. // check data for error
  16.  
  17. if (data.includes("ERROR:")) {
  18. var errorMessage = data;
  19. document.getElementById('error').innerHTML = errorMessage;
  20. return false;
  21. } else {
  22. window.location = '${pageContext.request.contextPath}/jsp/menu.jsp';
  23. }
  24. },
  25. error: function(data){
  26. alert("fail");
  27. }
  28. });
  29. });
  30. $('#signup').click(function(event){
  31. event.preventDefault();
  32. window.location = '${pageContext.request.contextPath}/jsp/new_user.jsp';
  33. });
  34. });
  35. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement