views:

49

answers:

2

I have a django application that creates xls and txt files.

I'm trying to create a button which sends a jQuery.get request to django, django then returns a freshly created file to jQuery which in turn pops open a save as dialog.

My code looks like this:

jQuery("#testButton").live("click",function()
{
    jQuery.jGrowl("click");
    jQuery.get("/filetest",function(data){});

});


<div id="testButton" class="button">CLICK TO TEST</div>

Getting the file to jQuery is easy, but I have no idea how to then raise a Save As dialog.

Any assistance would be fantastic!

A: 

How about a window.open invocation which opens a server-side file that sends a Content-Type of a file attachment along with the file contents in the Content Body?

meder
+2  A: 

you can use iframe in your page and change with jquery the source, to the file you want to download.

this code put in html body :

<iframe id="download" style="width:0px;height:0px;display:none;"></iframe>

and the jquery in event of click look like:

$('#download').attr("src",location.href+"&make_excell=1");

in your sever side send the file back when the request make_excell with a content-type

Haim Evgi
worked a treat, thanks!
danspants
i found another way via pluginhttp://www.filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/
Haim Evgi