-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.js
More file actions
52 lines (39 loc) · 1.21 KB
/
Copy pathlog.js
File metadata and controls
52 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
window.onload=checklogin();
function checklogin() {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'phpvariables.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
xhr.onload = function () {
if (this.status == 200) {
if(this.responseText){
document.getElementById("navlogin").innerHTML="Logout";
}else{
document.getElementById("navlogin").innerHTML="Login";
}
}
}
xhr.send("userid_availability");
}
function logout() {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'phpvariables.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
xhr.onload = function () {
if (this.status == 200) {
if(this.responseText){
window.location.href="login";
}
}
}
xhr.send("logout");
}
document.getElementById("navlogin").addEventListener("click",redirlogin);
function redirlogin(){
if(document.getElementById("navlogin").innerHTML=="Login"){
window.location.href="login";
}else{
if(confirm("Do you want to Logout?")){
logout();
}
}
}