我有一個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});
});