flask 发送ajax

前端

python 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="https://cdn.lyshark.com/javascript/jquery/3.5.1/jquery.min.js" type="text/javascript"></script>

<form id="psmForm">
    <input type="text" value="111" name="t1">
    <input type="input" id="send">
</form>

<form id="psmForm2">
    <input type="text" value="111" name="t1">
    <input type="input" id="send2">
</form>



<script type="text/javascript">

    $('#send').click(function () {
        $.ajax({
            url: "/",
            contentType: "POST",
            data: $("#psmForm").serialize(),
            success: function (data) {
                if (data == "1") {
                    alert("请求已经提交.");
                }
            },
            error: function () {
                alert("执行失败了...")
            }
        })
    })



</script>


</body>
</html>

后端

python 复制代码
from flask import Flask,request,render_template,redirect

app = Flask(__name__)


@app.route('/',methods=['GET','POST'])
def test():
    if request.method == "GET":
        return render_template('01.html')
    print('1111')
    print(request.form.get('psm'))
    return redirect('https://www.baidu.com')



if __name__ == '__main__':
    app.run()
相关推荐
兵慌码乱3 小时前
面向桌面端的资产管理系统分层架构设计与核心模块实现
python·系统架构·sqlite·pyqt5·数据库设计·桌面应用开发·mvc架构
hboot5 小时前
AI工程师第三课 - 机器学习基础
python·scikit-learn·kaggle
顾林海9 小时前
Agent入门阶段-编程基础-Python:流程控制
python·agent·ai编程
呱呱复呱呱12 小时前
Django CBV 源码解读:一个请求是怎么找到你的 get() 方法的
python·django
曲幽17 小时前
刚部署的 LibreTranslate 频频翻车?我掏出了 20 年前的 StarDict 词典,用 FastAPI 搭了个本地词典翻译 API
python·fastapi·web·translate·goldendict·libretranslate·stardict·pystardict
荣码17 小时前
用Streamlit给AI应用套个界面,10行代码出Web页面
java·python
兵慌码乱1 天前
基于Python+PyQt5+SQLite的药房管理系统实现:事务一致性与界面解耦全流程解析
python·sqlite·信号与槽·pyqt5·数据库设计·桌面应用开发·事务处理
金銀銅鐵1 天前
[Python] 体验用欧几里得算法计算最大公约数的过程
python·数学
FreakStudio1 天前
W55MH32L-EVB 上手测评:硬件 TCP/IP 加持的以太网单片机,MicroPython 零门槛开发
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy·电子计算机
用户0332126663671 天前
使用 Python 从零创建 Word 文档
python