2 回答
TA贡献1786条经验 获得超11个赞
不要使用 Ajax 来添加新书它会让用户感到困惑,因为他不知道它是否被添加到了其中idlist,Form POST而是使用了。
在script.js删除以下块
$("#q").on('typeahead:selected', function a(eventObject, suggestion, name) {
...
...
});
并将所选项目添加到输入表单,替换
display: function(suggestion) { return null; },
和
display: function(suggestion) { return suggestion.Title; },
制作表单POST,adjust.html替换
<form action="/adjust">
....
<input class="form-control" id="q" placeholder="Title, Author" type="text"/>
和
<form action="/addbook" method="POST">
....
<input class="form-control" id="q" placeholder="Title, Author" name="title" type="text" autocomplete="off" />
和addBook()方法
@app.route("/addbook", methods=["GET", "POST"])
def addbook():
"""Add selected book"""
if request.method == "POST" and request.form.get("title"):
Title = request.form.get("title")
insert_book = db.execute("INSERT INTO idlist (id,Title1, Status) VALUES (:id, :Title1, :Status)", id=session["user_id"], Title1=Title, Status="Not started")
return redirect("/")
# no "title" in the form, return to Add new book page
return redirect("/adjust")
添加回答
举报