-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck.js
46 lines (41 loc) · 1.15 KB
/
check.js
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
var xmlHttp = createXmlRequestObject();
function createXmlRequestObject(){
var xmlHttp;
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
else{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
function process(){
// configure -> handleresponse -> communicate
if(xmlHttp.readyState == 0 || xmlHttp.readyState == 4){
var username = encodeURIComponent(document.getElementById("username").value);
xmlHttp.open("GET","check.php?username="+username,true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}
else{
setTimeout('process()',1000);
}
}
function handleServerResponse(){
if(xmlHttp.readyState == 4){
check = document.getElementById('check');
if(xmlHttp.status == 200){
try{
msg = xmlHttp.responseText;
check.innerHTML = msg;
setTimeout('process()',1000);
}
catch(e){
alert(e.toString());
}
}
else{
check.innerHTML += 'SOMETHING IS WRONG';
}
}
}