zoukankan      html  css  js  c++  java
  • flask接收前台的ajax的post数据

    html

      

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/static/css/index.css">

    <script src="/static/js/jquery.min.js"></script>
    </head>
    <body>
    <input type="text" name="usernam" id="username">
    <input type="password" name="password" id="password">
    <button id="btn">点击</button>
    <script>
    $(function(){
    $("#btn").click(function(){
    var username=$('#username').val();
    var password=$('#password').val();
    var data= {
    data: JSON.stringify({
    'username': username,
    'password': password
    }),
    }
    $.ajax({
    url:'http://localhost:7999/sendAjax2',
    type:'POST',
    data:data,
    dataType: 'json',
    success:function(res){
    console.log(res)
    console.log(0)

    },
    error:function (res) {
    console.log(res);
    console.log(1)
    }

    })
    })
    })
    </script>
    </body>
    </html>

    @app.route('/sendAjax2', methods=['POST'])
    def sendAjax2():
        # password = request.form.get('password')
        # username = request.args.get('username')
    
        data = json.loads(request.form.get('data'))
        username = data['username']
        password = data['username']
        print (username)
        print (password)
        return "46575"
    

      

  • 相关阅读:
    window10-jmeter安装
    软件开发模型
    软件测试的原则和流程
    手机APP测试
    优秀的软件测试工程师
    自动化测试
    测试用例
    软件测试功能分类
    ios-prefix文件最全
    催收策略及催收评分卡搭建
  • 原文地址:https://www.cnblogs.com/wanghaonull/p/6340491.html
Copyright © 2011-2022 走看看