我一直在搜索,但我不太明白ajax是如何工作的。有人能解释一下这是怎么回事吗?
$.ajax({
url: "{{ url_for( 'app.slideshow.<tag>' ) }}",
type: "",
data: {'param':},
dataType: "",
success : function(response)
{
}
我要做的是查看document.getElementsByClassName(当前)是否已更改。如果有,它会向app.py询问当前页面上的评论和标记,并在不刷新的情况下更新页面。我也不知道要写什么才能在app.py上收到这个。
我将包含app.py,但它不好。
from flask import Flask,session,url_for,request,redirect,render_template
import api,db
app = Flask(__name__)
#app.secret_key = "secret"
@app.route('/slideshow/<tag>', methods=['GET', 'POST'])
def slide():
if request.method=="GET":
pic = request.get('current').href
taglist = db.getTaglist()
tags = db.getTags(pic)
piclist = db.getPics(<tag>)
commentlist = db.getComments(pic)
return render_template("slide.html", taglist = taglist, tags =tags, piclist =piclist, commentlist = commentlist, url = url)
else:
button = request.form['button']
pic = request.get('current').href
if button=="submit":
aComment = request.form['comment']
db.addComment(pic,aComment)
elif button == "submitnewtag":
if request.form['Addnewtag']
aTag = request.form['Addnewtag']
db.addTag(pic,aTag)
else:
aTag = request.form['select1']
db.addTag(pic,aTag)
if __name__=="__main__":
app.debug=True
app.run(port=5300)
通常,服务器上的ajax处理程序应该返回XML或JSON(我认为JSON更好)及其所需的数据。
所以,在获得hanler中的信息后,将其dum到JSON并返回到客户端。
在客户机上,Javascript接收这个JSON,然后应该动态地创建html元素并将它们插入到页面主体中。
从探索烧瓶的创造者开始。
相关问题 更多 >
编程相关推荐