Flask:如何使用 load() 从 ajax 获取参数?

Flask: How do i get parameters from ajax using load()?

我想通过单击元素更改年份来重新加载日历。我的 js 看起来像这样:

var y = document.getElementById('yy').getAttribute('data-value');
$(document).ready(function(){
    $('.prev').click(function(){
        $(".main_content").empty();
        $('.main_content').load("calendar", {'year': int(yy)-1});
    });
});

如何使用Flask获取服务端的参数?

我想要这样的东西:

year = request.args.get('year')
# some more code
return render_template('calendar.html', year=year, #more params)

数据作为表单数据通过 POST 请求发送。使用 request.form 对象获取数据。

@app.route('/calendar', methods=['GET', 'POST'])
def calendar():
    if request.method == 'POST':
        year = request.form.get('year', type=int)
        # Your code here.
        return 'Your reply here.'
    return render_template('calendar.html')