Guest User

Untitled

a guest
Sep 19th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. /* ---------------------------- */
  2. /* XMLHTTPRequest Enable */
  3. /* ---------------------------- */
  4. function createObject() {
  5. var request_type;
  6. var browser = navigator.appName;
  7. if(browser == "Microsoft Internet Explorer"){
  8. request_type = new ActiveXObject("Microsoft.XMLHTTP");
  9. }else{
  10. request_type = new XMLHttpRequest();
  11. }
  12. return request_type;
  13. }
  14.  
  15. var http = createObject();
  16.  
  17. /* -------------------------- */
  18. /* LOGIN */
  19. /* -------------------------- */
  20. /* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
  21. var nocache = 0;
  22. function login() {
  23. // Optional: Show a waiting message in the layer with ID ajax_response
  24. document.getElementById('login_response').innerHTML = "Loading..."
  25. // Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
  26. var user = encodeURI(document.getElementById('loginuser').value);
  27. var psw = encodeURI(document.getElementById('loginpass').value);
  28. // Set te random number to add to URL request
  29. nocache = Math.random();
  30. // Pass the login variables like URL variable
  31. http.open('get', 'logincheck.php?user='+user+'&pass='+psw+'&nocache = '+nocache);
  32. http.onreadystatechange = loginReply;
  33. http.send(null);
  34. }
  35.  
  36. function loginReply() {
  37. if(http.readyState == 4){
  38. var response = http.responseText;
  39. if (response === false){
  40. // if login fails
  41. document.getElementById('login_response').innerHTML = '<div class="alert"><strong>Warning!</strong> Looks like you entered something wrong!.</div>';
  42. // else if login is ok show a message: "Welcome + the user name".
  43. } else {
  44. document.getElementById('login_response').innerHTML = '<div class="alert alert-success"><strong>Hey!</strong> Welcome back, ' + response + '</div>';
  45. }
  46. }
  47. }
Add Comment
Please, Sign In to add comment