index.html
<a href="{{url_for('all',name='other')}}">其他</a>
<a href="{{url_for('all',name='jost')}}">JOST</a>
//使用tojson,防止空格、'、"等字符被转义成其他字符
var pro = eval('{{index|tojson}}');
var data = {
'selectproId':$("#selectproId").val(),
};
$.ajax({
type:'POST',
url:"/all/"+pro,
data:data,
dataType:'json',
success:function(data){
}
});
@app.route('/all/<name>', methods=['GET','POST'])
def all(name):
if request.method == 'GET':
conn = pymysql.connect(host='localhost', port=3306, user='user', passwd='passwd.', db='products',
charset='utf8')
cursor = conn.cursor()
cursor.execute("select * from all_list")
data = cursor.fetchall()
conn.close()
if name== 'jost':
return render_template("all.html", data=data, index='jost')
else:
return render_template("all.html", data=data, index='other')
if __name__ == '__main__':
app.run(debug=True)