单击按钮,sqlite3刷新数据

时间:2018-08-15 08:41:54

标签: javascript jquery sqlite web2py

尝试时,我的代码基本上运行良好。但是,当我尝试访问发布到sqlite3数据库的数据时,我无法在sqlite3中找到最后更新的文本。相反,我得到了以前更新的文本,而不是当前的文本。有没有一种方法可以在发布文本后刷新sqlite3 db,以便我可以访问最近的文本。我想将最近的文本用于某些NLP函数,以便回复给用户。使用sqlite update对我不起作用,因为响应是相同的。这是html代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>convForm - example</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
    <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
    <link href="{{=URL('static', 'css/jquery.convform.css')}}" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link href="{{=URL('static', 'css/demo.css')}}" rel="stylesheet" type="text/css" />
</head>
<body>
    <section id="demo">
        <div id="target"></div>
        <div class="vertical-align">
            <div class="container">
                <div class="row">
                    <div class="col-sm-6 col-sm-offset-3 col-xs-offset-0">
                        <div class="card no-border">
                            <div id="chat" class="conv-form-wrapper">
                                <form enctype = "multipart/form-data" action = "{{= URL()}}" method = "post" class="hidden">
                                    <select data-conv-question="Hello! I'm a bot created from a HTML form. Can I show you some features? (this question comes from a select)">
                                        <option value="yes">Yes</option>
                                        <option value="sure">Sure!</option>
                                    </select>
                                    <input type="text" name="message" data-conv-question="Alright! First, type one word e.g. 'exercise', or ask a question.|Okay! you can type one word e.g. 'Soy', or ask a question.">
                                    <input type="text" data-conv-question="{{=code}}" data-no-answer="true">                                       
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>        
    </section>
    <script type="text/javascript" src="jquery-1.12.3.min.js"></script>
    <script src="{{=URL('static','js/jquery-1.12.3.min.js')}}" type="text/javascript"></script>
    <script src="{{=URL('static','js/autosize.min.js')}}" type="text/javascript"></script>
    <script src="{{=URL('static','js/jquery.convform.js')}}" type="text/javascript"></script>

    <script>
        var rollbackTo = false;
        var originalState = false;
        function storeState(stateWrapper) {
            rollbackTo = stateWrapper.current;
            console.log("storeState called: ",rollbackTo);
        }
        function rollback(stateWrapper) {
            console.log("rollback called: ", rollbackTo, originalState);
            console.log("answers at the time of user input: ", stateWrapper.answers);
            if(rollbackTo!=false) {
                if(originalState==false) {
                    originalState = stateWrapper.current.next;
                        console.log('stored original state');
                }
                stateWrapper.current.next = rollbackTo;
                console.log('changed current.next to rollbackTo');
            }
        }
        function restore(stateWrapper) {
            if(originalState != false) {
                stateWrapper.current.next = originalState;
                console.log('changed current.next to originalState');
            }
        }
        jQuery('#myform').submit(function() {
            ajax('{{=URL('view_searche')}}', '#myform', 'target');
            return false;
        });
    </script>

</body>
</html>

控制器代码:

def viewer():
form = SQLFORM(Post, formstyle='table3cols').process()
    if request.vars:
        r = [request.vars.name]
        codes.append(r[0])
        db.post.insert(name=codes[0])
    row = db(db.post.author== auth.user.id).select(db.post.id, db.post.name, orderby=~db.post.id, limitby=(0,1)).first()
    code = row.name if row else None
    return dict(code=code)

0 个答案:

没有答案