-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlogin.js
More file actions
56 lines (44 loc) · 1.18 KB
/
login.js
File metadata and controls
56 lines (44 loc) · 1.18 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
53
54
55
56
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
var xmlHttp;
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else{
xmlHttp = new ActiveXObject("microsoft.XMLHTTP");
}
return xmlHttp;
}
function login(){
var username=document.getElementById('username').value;
var password=document.getElementById('password').value;
var senddata="username="+username+"&password="+password;
username.value='';
password.value='';
if(xmlHttp){
try{
xmlHttp.open("POST","Http://moodshare.herokuapp.com/login",true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Access-Control-Allow-Origin","*");
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(senddata);
}catch(e){
alert( e.toString() );
}
}
}
function handleServerResponse(){
theD = document.getElementById('theD');
if(xmlHttp.readyState==4){
if(xmlHttp.status==202){
try{
text=xmlHttp.responseText;
theD.innerHTML+=text
}catch(e){
alert(e.toString());
}
}else{
alert(xmlHttp.statusText);
}
}
}
username.focus();