-
Notifications
You must be signed in to change notification settings - Fork 101
/
index.html
88 lines (77 loc) · 2.39 KB
/
index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<html>
<body>
<h1>CrossRequest</h1>
<input id="file" type="file" name="file" />
<button id="upload">upload</button>
<script>
setTimeout(run, 1000)
function run () {
window.crossRequest({
url: 'http://caibaojian.com/ajax-jsonp.html',
method: 'GET',
query: {
a: 1
},
success: function (res, header) {
console.log(header)
}
})
//test get
window.crossRequest({
url: 'http://127.0.0.1:3000/api',
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
data: {
a: 1,
b: 2,
c: {
t: 1
}
},
success: function (res) {
console.log(arguments)
}
})
//test error get
window.crossRequest({
url: 'http://127.0.0.1:3000/error_get',
method: 'GET',
error: function (err, header) {
console.log(err)
}
})
//test form-data upload
var file = document.getElementById('file');
document.getElementById('upload').addEventListener('click', function () {
window.crossRequest({
url: 'http://127.0.0.1:8081/upload',
method: 'POST',
data: {
name: 'hello',
id: '19'
},
files: {
file: 'file'
},
success: function (res) {
alert(res)
}
})
})
//test single-upload
document.getElementById('upload').addEventListener('click', function () {
window.crossRequest({
url: 'http://127.0.0.1:8081/upload/single',
method: 'POST',
file: 'file',
success: function (res) {
alert(res)
}
})
})
}
</script>
</body>
</html>