Sijax obj_response不会提醒或修改烧瓶中的任何内容?

时间:2016-12-17 12:06:58

标签: python sijax

  
    

我的表单通过sijax请求提交数据并确认我使用obj_response的提交。我尝试了obj_response.alert()以及obj_response.html(),但没有任何效果

         

我的代码:

  
from flask import Flask, render_template, request, flash, g, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
import flask_sijax
import os
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///Login.sqlite3"
path = os.path.join('.', os.path.dirname(__file__), 'static/js/sijax1/')
app.secret_key = 'super secret key'
app.config['SESSION_TYPE'] = 'filesystem'
app.config['SIJAX_STATIC_PATH'] = path
app.config['SIJAX_JSON_URI'] = 'static/js/sijax/json2.js'

db = SQLAlchemy(app)
flask_sijax.Sijax(app)


class Signup(db.Model):
    ID = db.Column("ID", db.String(10), primary_key=True)
    Fname = db.Column(db.String(20))
    LName = db.Column(db.String(20))
    Password = db.Column(db.String(20))


    def __init__(self, id, fname, lname, password):
        self.ID = id
        self.Fname = fname
        self.LName = lname
        self.Password = password


@flask_sijax.route(app, '/signup')
def home():
    def caller(obj_response, values):
        newuser = Signup(values['ID'], values['fname'], values['lname'], values['Password'])
        db.session.add(newuser)
        db.session.commit()
        obj_response.html("#result", "Successfully signed up")


    if g.sijax.is_sijax_request:
        g.sijax.register_callback('call', caller)
        return g.sijax.process_request()
    return render_template("first.html")


@app.route("/success", methods=['POST', 'GET'])
def success():

    records = db.session.query(Signup).all()
    return render_template("second.html", records=records)

if __name__ == "__main__":
    db.create_all()
    app.run(host="127.0.0.1", port=2908, debug=True, threaded=True)
  
    

我的HTML文件

  
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Sign Up</title>
    <script type="text/javascript" src="{{url_for('static',filename='Signup.js')}}"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script type="text/javascript" src="{{url_for('static', filename='js/sijax/sijax.js')}}"></script>
    <script type="text/javascript">{ {g.sijax.get_js()|safe }}</script>

    <link rel="stylesheet" href="{{url_for('static', filename='styles/firstcss.css')}}">
</head>
<body style = "font-family: Lato">
    <div style="padding-left: 5%;padding-top:0.2%;padding-bottom: 0px;height: 4%;width: 100%;background-color: #11557C;margin-left: 0px;margin-top: 0px;">
    <h2>Welcome to my site</h2><br>
    </div>
    <div style="margin-left: 70%" width="100%">
        <form method="post" action="http://127.0.0.1:2908/success">
        <input type="submit" style="position: relative;margin-top: 5%;margin-left:20%" value="View Logs">
        </form>
    </div>

    <div style="width:80%">
    <form  name="form1" id="form1" method="post" style="padding-top: 1%"><!--action = "http://127.0.0.1:2908/success"!-->
        <label id="head" style="font-size: 20px;padding-bottom: 1%;">Sign Up</label><br>
        <label id="user" style="font-size: 16px;margin-top: 5%;">Username</label><br>
        <input type="text" name = "ID" placeholder = "Username" style = "padding-left: 0.2%;"><br><br>
        <label style="font-size: 16px">First name</label><br>
        <input type="text" name = "fname" id="fname" placeholder = "First name" style = "padding-left: 0.2%"><br><br>
        <label style="font-size: 16px">Last name</label><br>
        <input type="text" name = "lname" placeholder = "Last name" style = "padding-left: 0.2%"><br><br>
        <label style="font-size: 16px">Password</label><br>
        <input type = "password" name = "Password" placeholder = "Password" style = "padding-left: 0.2%"><br><br><br>
        <input type = "submit" onclick="return validate()" value = "Sign up" style="width:50%;height: 40px;margin-left: 12%;background-color: #11557C;color: black">
    </form>
    </div>
    <h3 id="result" >RESULT</h3>


</body>
</html>

1 个答案:

答案 0 :(得分:0)

我注意到当使用高于1.5.1的jQuery版本时,Sijax停止工作 所以尝试替换:

  

https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js

使用:

  

https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

但是我在这一点上没有找到其他开发者或论坛的任何其他确认,只是我自己。