forked from Tencent/APIJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
162 lines (152 loc) · 4.23 KB
/
index.html
File metadata and controls
162 lines (152 loc) · 4.23 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<script type="text/javascript" language="JavaScript" charset="UTF-8" src="apijson.js" ></script>
<title>APIJSON Test</title>
<style type="text/css">
html,body,div{
width: 100%;
height:100%;
position:relative;
margin:0;
padding:0;
}
.match{
width: 100%;
height:100%;
margin: 0;
padding:0;
}
.top{
width: 100%;
height:40px;
padding-left: 2%;
padding-right: 2%;
text-decoration-color: aquamarine;
}
.title{
width: auto;
height:20px;
padding:0;
text-overline-color: aquamarine;
}
.center{
width: 100%;
height: 68%;
margin: 0;
padding:0;
}
.bottom{
width: 100%;
height:40px;
margin: 0;
padding:0;
}
.horizontal{
width: 49%;
height:100%;
margin: 0;
padding:auto;
}
.url{
width: 74%;
height:50px;
margin: 0;
}
.button{
width: 20px;
height:10px;
margin: 0;
padding:0;
}
.send{
width: 25%;
height:50px;
margin: 0;
padding:0;
}
</style>
</head>
<body>
<div class="match">
<div class="top" aria-orientation="horizontal">
<h2 class="title" align="left">APIJSON Test</h2>
<h2 class="button">Demo</h2>
<button class="button" align="right">GET</button>
</div>
<div class="center" aria-orientation="horizontal">
<textarea class="horizontal" id="input" onkeyup="javascript:onChange()">
{
"[]":{
"User":{
"sex":1
}
}
}
</textarea>
<textarea class="horizontal" id="output" readonly>
initializing...
</textarea>
</div>
<div class="bottom" aria-orientation="horizontal">
<input class="url" type="text" placeholder="input url here" id="url" />
<button class="send" id="ok" onclick="javascript:send()">Send</button>
</div>
</div>
<script type="text/javascript" language="JavaScript" charset="UTF-8" >
var input = document.getElementById("input");
var output = document.getElementById("output");
var url = document.getElementById("url");
var ok = document.getElementById("ok");
url.value = new String(url_get);
var inputted;
var handler;
/**计时回调
*/
function handle(before) {
if (inputted != before) {
clearTimeout(handler);
return;
}
//格式化输入代码
try {
input.value = format(input.value);
ok.disabled = false;
output.value = "OK, click [Send] button to send a request";
} catch(e) {
console.log(e);
ok.disabled = true;
output.value = "Error! Please check and modify JSON request!";
}
}
/**输入内容改变
*/
function onChange() {
inputted = new String(input.value);
clearTimeout(handler);
handler = setTimeout(function () {
handle(inputted);
}, 2*1000);
}
onChange();
/**发送请求
*/
function send() {
clearTimeout(handler);
var json = JSON.parse(input.value);
output.value = "requesting...";
var rq = request(url.value, json, true, function () {
if (rq.readyState !== 4) {
return;
}
if (rq.status === 200) {
output.value = format(rq.responseText);
} else {
output.value = "Response(GET):\nurl = " + rq.url + "\nstatus = " + rq.status + "\nerror = " + rq.error;
}
});
}
</script>
</body>
</html>