I suggest replacing your ajax request with a hidden iframe, and then when your server returns the specified file, it will automatically ask the user to download it.
//name of iframe var strName = ("uploader" + (new Date()).getTime()); // the iframe var jFrame = $( "<iframe name=\"" + strName + "\" src=\"about:blank\" />" ).css( "display", "none" ); jFrame.load(function( objEvent ){ // at this point the user should have been asked to download a file. // Remove the iFrame from the document. // Because FireFox has some issues with // "Infinite thinking", let put a small // delay on the frame removal. setTimeout(function(){ jFrame.remove(); },100); }); var form = $('<form>').attr( "action", "upload_act.cfm" ) .attr( "method", "post" ) .attr( "enctype", "multipart/form-data" ) .attr( "encoding", "multipart/form-data" ) .attr( "target", strName ); form.append('<input type="hidden" name="somename">').val("someval"); $( "body:first" ).append( jFrame, form );
(The above code was originally adapted from http://www.bennadel.com/blog/1244-ColdFusion-jQuery-And-AJAX-File-Upload-Demo.htm )
An alternative would be to make this a two-step process. Step 1 generates the file and returns the URL, step 2, which the user clicks on the download (this will be an anchor tag pointing to the specified URL).
source share