Return data from database using Flask, Flask-sqlalchemy, and jQuery
<p>I want div.disp to get the id of the data to be added to the database, it works for the first add but for the next ones, it will be the same id as the the first add.</p>

<pre><code>@app.route('/')
@app.route('/index')
def index():
    tsklst = models.User.query.order_by('id asc').all()
    last = tsklst[len(tsklst)-1].id+1
    return render_template('index.html',last=last)

@app.route('/_add')
def add_(): 
    toDo = request.args.get('task')
    u = models.User(task = str(toDo))
    db.session.add(u)
    db.session.commit()
    return render_template('index.html')
</code></pre>

<p>by my idea, div.disp should have an attribute id of the last+1 added data into the database</p>

<pre><code>$(document).ready(function(){
    $('#btnTask').click(function(){
        if ($('#txtTask').val()!=''){
            $.getJSON('/_add',{
                task: $('#txtTask').val(),
            });
            $('.content').append("&lt;div class='disp' id='{{ last }}'&gt;&lt;div class='left'&gt;"+$('#txtTask').val()+"&lt;/div&gt;&lt;input type='checkbox' class='chkbk'&gt;&lt;/div&gt;");
        }
        $('#txtTask').val('');
        $('#txtTask').focus();
    });
});
</code></pre>

<p>I'm currently looking at db.session.refresh() but I don't quite understand it</p>