commit
9735b87c45
2 changed files with 66 additions and 0 deletions
@ -0,0 +1,38 @@ |
|||||
|
from flask import Flask, jsonify |
||||
|
from flask_cors import CORS |
||||
|
import threading |
||||
|
import paramiko |
||||
|
import time |
||||
|
|
||||
|
#region 全局 |
||||
|
|
||||
|
app = Flask(__name__) |
||||
|
CORS(app) |
||||
|
port = 15002 |
||||
|
|
||||
|
#endregion |
||||
|
|
||||
|
#region 接口 |
||||
|
|
||||
|
# 测试用 |
||||
|
@app.route('/') |
||||
|
def hello(): |
||||
|
return 'hi. —— CheckGPUsWeb' |
||||
|
|
||||
|
@app.route('/data', methods=['GET']) |
||||
|
def get_data(): |
||||
|
data = {'name': 'John', 'age': 25, 'city': 'New York'} |
||||
|
return jsonify(data) |
||||
|
|
||||
|
# 开始连接服务器 |
||||
|
def connect_server(): |
||||
|
pass |
||||
|
|
||||
|
#endregion |
||||
|
|
||||
|
# 测试 |
||||
|
def test(): |
||||
|
app.run(debug=True, port=port) |
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
test() |
@ -0,0 +1,28 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
|
<title>Fetch JSON from Flask</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
<h1>Fetch JSON from Flask Example</h1> |
||||
|
<button onclick="fetchData()">Fetch Data</button> |
||||
|
<div id="output"></div> |
||||
|
|
||||
|
<script> |
||||
|
function fetchData() { |
||||
|
fetch('http://lxblxb.top:15002/data') // 发起 GET 请求到 Flask 服务器的 '/get_data' 路径 |
||||
|
.then(response => response.json()) // 解析 JSON 响应 |
||||
|
.then(data => { |
||||
|
// 处理 JSON 数据 |
||||
|
console.log(data); |
||||
|
document.getElementById('output').innerHTML = '<pre>' + JSON.stringify(data, null, 2) + '</pre>'; |
||||
|
}) |
||||
|
.catch(error => { |
||||
|
console.error('Error fetching data:', error); |
||||
|
}); |
||||
|
} |
||||
|
</script> |
||||
|
</body> |
||||
|
</html> |
Loading…
Reference in new issue