我有一个Django响应发送文件给用户,然后仅通过浏览器忽略。我怎样才能打开文件保存对话框来保存呢?如何使用jQuery保存文件响应?
这里是我的Django代码:
mimetype = "application/x-unknown"
file = somefilefromthedatabase
response = HttpResponse(file, mimetype=mimetype)
response["Content-Disposition"]= "attachment; filename=%s" % os.path.split(file.name)[1]
return response
当我访问视图中直接产生这种情况,将文件保存到数据库中。当通过jQuery访问它时,没有任何反应。 jscode是在这里:
$(".jp-download").click(function(){
current=$("#download").data('current').find('.id').text();
$.post('/actions/',{action:'download',item:current});
});