-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-restest.html
66 lines (58 loc) · 1.6 KB
/
05-restest.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!doctype html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>无刷投票</title>
</head>
<script type = "text/javascript">
function createXHR()
{
var xhr = null;
if(window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
return xhr;
}
function vote()
{
//1:制造xhr
var xhr = createXHR();
//2:打开连接
xhr.open('GET','./05-restest.php',true);
//3:发送请求
xhr.send(null);
//4:获取返回信息
// alert(xhr.responseText);
//绑定状态变化函数
xhr.onreadystatechange = function () {
if(this.readyState == 4 && this.status == 200) {
var str = '';
str = '状态码是' + this.status + '<br />';
str = str + '状态文字是' + this.statusText + '<br />';
str = str + '返回类型是:' + this.getResponseHeader('Content-Type') + '<br />';
str = str + '返回的主体长度是' + this.getResponseHeader('Content-Length') + '<br />';
str = str + '返回的主体内容是' + this.responseText + '<br />';
str = str + '所有头信息' + this.getAllResponseHeaders();
document.getElementById('progress').innerHTML = str;
}
}
1
}
</script>
<body>
<div>
<p><img src = './wmc.jpg' /></p>
<p><input type = 'button' value = '投票方法2' onclick = "vote();"/></p>
</div>
<div id='progress'>
</div>
</body>
</html>