flask ajax回调(flask 12)

jquery.ajax()函数参数:
url:
type:GET
data
datatype
complete:请求完成时回调函数
success:请求成功
error:请求失败

返回的三种ajax数据

return render_tempalte('xx.html')
return jsonify(xxx)
return '',204

例子

from flask import Flask,make_response,json
from jinja2.utils import generate_lorem_ipsum

app = Flask(name)

@app.route('/post')
def show_post():
post_body = generate_lorem_ipsum(n=2)
return '''

A very long post


%s



''' % post_body

@app.route('/more')
def load_post():
return generate_lorem_ipsum(n=1)

if name == 'main':
app.run(
host='0.0.0.0',
port=8888,
debug=True
)

你可能感兴趣的:(flask ajax回调(flask 12))