我有以下路线:
@app.route('/download/', methods=['GET'])
def download():
output_filename = request.args.get('output_filename')
data = dict(foos=[1,2,3,3,2,1], bars=[7,7,7,7,7,7])
df = pd.DataFrame(data)
result = df.to_csv(index=False)
response = make_response(result)
response.headers['Content-Disposition'] = f'attachment; filename={output_filename}'
response.headers['Cache-Control'] = 'must-revalidate'
response.headers['Pragma'] = 'must-revalidate'
response.headers['Content-type'] = 'application/csv'
return response
我用AJAX调用它如下:
function download(data, handler = null) {
let data = {output_filename: "foo.csv"};
let url = "/download/";
$.ajax({
type: "GET",
url: url,
data: data,
success: function(data) {
console.log('success');
},
});
}
但是,客户端什么都没有出现。我是不是漏掉了什么
我对node比ajax更熟悉(我在nodejs中遇到了相同的问题,我在这里修复了stackoverflow),但这可能会有所帮助:
从How do I make jQuery wait for an Ajax call to finish before it returns?
相关问题 更多 >
编程相关推荐