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()
相关推荐
用户83562907805114 分钟前
Python 实现 Excel 条件格式自动化
后端·python
深蓝电商API1 小时前
Scrapy管道Pipeline深度解析:多方式数据持久化
爬虫·python·scrapy
噎住佩奇1 小时前
(Win11系统)搭建Python爬虫环境
爬虫·python
basketball6161 小时前
python 的对象序列化
开发语言·python
rgeshfgreh2 小时前
Python流程控制:从条件到循环实战
前端·数据库·python
luoluoal2 小时前
基于python大数据的电影市场预测分析(源码+文档)
python·mysql·django·毕业设计·源码
幻云20102 小时前
Python深度学习:从入门到实战
人工智能·python
Zoey的笔记本2 小时前
敏捷与稳定并行:Scrum看板+BPM工具选型指南
大数据·前端·数据库·python·低代码
开开心心就好3 小时前
图片格式转换工具,右键菜单一键转换简化
linux·运维·服务器·python·django·pdf·1024程序员节
骥龙3 小时前
1.2下、工欲善其事:物联网安全研究环境搭建指南
python·物联网·安全