45 lines
1.6 KiB
HTML
45 lines
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
// $.ajax({
|
|
// url: 'https://api.lihe-control.com/sel/eqbyid/1', // 请求地址
|
|
// type: 'get', // 请求方式
|
|
// data: '', //携带到后端的参数
|
|
// contentType: 'application/x-www-form-urlencoded', // 传参格式(默认为表单) json为application/json
|
|
// dataType: 'json', //期望后端返回的数据类型
|
|
// success: function (res) {
|
|
// console.log('res', res);
|
|
// }, // 成功的回调函数 res就是后端响应回来的数据
|
|
// error: function(err) {
|
|
// console.log('err', err);
|
|
// } // 失败的回调函数
|
|
// })
|
|
|
|
var xhr = new XMLHttpRequest(); // IE8/9需用window.XDomainRequest兼容
|
|
|
|
// 前端设置是否带cookie
|
|
xhr.withCredentials = true;
|
|
|
|
xhr.open('get', 'https://api.lihe-control.com/sel/eqbyid/1', true);
|
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
|
|
xhr.setRequestHeader('token','eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4NzRmMmRhNTI3NTU0MDAwYjYxODg0OWUzM2Y1ZGI1YyIsInN1YiI6IjEiLCJpc3MiOiJsaCIsImlhdCI6MTY5NTQzODA3NSwiZXhwIjoxNjk1NDc0MDc1fQ.GeGOTtdr6DAsXl-6bqXATenYrcWKc18hRgmiWFgP2QI')
|
|
xhr.setRequestHeader("Access-Control-Allow-Methods", "GET, PUT, OPTIONS, POST");
|
|
xhr.send();
|
|
|
|
xhr.onreadystatechange = function() {
|
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
|
console.log(xhr);
|
|
}
|
|
};
|
|
|
|
</script>
|
|
</body>
|
|
</html> |