<div class="grid--cell fl1 lh-lg">
<div class="grid--cell fl1 lh-lg">
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, <a href="/help/reopen-questions">visit the help center</a>.
</div>
</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2012-12-02 20:13:48Z" class="relativetime">7 years ago</span>.</div>
</div>
</aside>
I'm been googling around, but I don't quite understand how ajax works. Could please somebody explain how this works?
$.ajax({
url: "{{ url_for( 'app.slideshow.<tag>' ) }}",
type: "",
data: {'param':},
dataType: "",
success : function(response)
{
}
What I'm trying to do is see if document.getElementsByClassName(current) has changed. If it has, it will ask app.py for comments and tags on current, and update the page without refreshing. I have no idea what to write to receive this on the app.py either.
I'll include my app.py, but it is not good.
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)
</div>
Usually, ajax handler on your server should return XML or JSON (I think JSON is better) with the data it needs.
So, after getting info in hanler, dum it to JSON and return to client.
On client, Javascript receives this JSON, and after that should dynamically create html elements and insert them in your page body.
Start by exploring this simple tutorial by Flask's creator.