-
Notifications
You must be signed in to change notification settings - Fork 0
/
typealine.html
52 lines (51 loc) · 1.67 KB
/
typealine.html
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
<!doctype html><title>post</title>
<input id=line type=text style=width:40em> <input id=btn type=button value="send" onclick="this.disabled=true;ajax_post('/qa/typealine',$('line').value,function(r){console.log(r);$('btn').disabled=false;$('line').focus();})">
<script>
function dbg(str){console.log(str)}
//function dbg(str){}
$=function(eid){return document.getElementById(eid);}
function ajax_post(uri,data,on_done){
dbg("ajax post to "+uri+"\n"+data);
var req=new XMLHttpRequest();
req.onreadystatechange=function(){
dbg("state: "+this.readyState);
switch(this.readyState){
case XMLHttpRequest.OPENED:
dbg(" OPENED");
dbg(" status:"+this.status);
dbg(" response length:"+this.response.length);
this.setRequestHeader('Content-Type','text/plain;charset=utf-8');
dbg(" data len:"+data.length);
dbg(" data:`"+data+"`");
this.send(data);
break;
case XMLHttpRequest.HEADERS_RECEIVED:
dbg(" HEADERS_RECEIVED");
dbg(" status:"+this.status);
dbg(" response length:"+this.response.length);
break;
case XMLHttpRequest.LOADING:
dbg(" LOADING");
dbg(" status:"+this.status);
dbg(" response length:"+this.response.length);
break;
case XMLHttpRequest.DONE:
dbg(" DONE");
dbg(" status:"+this.status);
dbg(" response length:"+this.response.length);
dbg(" response:\n"+this.response);
dbg("\n-------------------------------------------------");
if(on_done)on_done(this);
break;
default:throw"unknownstate";
}
};
req.onerror=function(){
dbg("error");
}
req.ontimeout=function(){
dbg("timeout");
}
req.open('post',uri,true);
}
</script>