Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
62 lines (61 loc) · 2.08 KB
/
Copy pathindex.html
File metadata and controls
62 lines (61 loc) · 2.08 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
<!--
* @Author: liuxiang
* @Date: 2022-07-11 18:06:12
* @LastEditors: liuxiang
* @LastEditTime: 2022-07-11 18:13:55
* @Description: file content
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>跨域测试</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.staticfile.org/bootstrap/4.5.3/css/bootstrap.min.css" >
</head>
<body>
<div class="container">
<h1 style="margin-top:50px">跨域测试</h1>
<!-- Content here -->
<p class="text-left">API地址:</p>
<input type="text" style="width:600px;height:30px;font-size:14px;" id="urlText" value=""/>
<p>
<p/>
<p class="text-left">Token:</p>
<input type="text" style="width:600px;height:30px;font-size:14px;" id="tokenTxt" value=""/>
<p>
<p/>
<input type="button" class="btn btn-outline-primary" id="cors" value="验证跨域"/>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script src="https://cdn.staticfile.org/popper.js/1.8.0/popper.min.js" ></script>
<script src="https://cdn.staticfile.org/bootstrap/4.5.3/js/bootstrap.min.js" ></script>
<script type="text/javascript">
$("#cors").on('click', function (event) {
event.preventDefault();
var url2 = $("#urlText").val();
$.get({
contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
url: url2,
beforeSend: function (xhr) {
if ($("#tokenTxt").val().trim()) {
/* Authorization header */
xhr.setRequestHeader("Authorization", "Bearer " + $("#tokenTxt").val());
}
},
success: function (data) {
alert("success");
},
error:function(data){
alert("failed");
}
})
});
</script>
</body>
</html>