I would set these headers in the excel.php script, and create a link directly to it. It is more or less a straight file download, created dynamically.
header("Cache-Control: no-cache"); header('Content-Type: application/octet-stream'); header("Content-Disposition: attachment; filename=MyExcelFile.xls"); ----- Original Message ----- From: "Travis Fisher" <[EMAIL PROTECTED]> To: "jQuery (English)" <jquery-en@googlegroups.com> Sent: Wednesday, March 05, 2008 7:00 PM Subject: [jQuery] jQuery AJAX Dynamic File Download > > I've got an export functionality built into my site, whereby users can > choose which rows of a data table to export. They export by clicking > an "Actions" dropdown and choosing "Export". This triggers an AJAX > call that posts which ids to export to a PHP script, which, in turn, > builds an Excel document on the fly and delivers it to the user. > > Here is my code: > > <input type="checkbox" id="selected1" name="Interviews[]" value="21" / >> > <input type="checkbox" id="selected2" name="Interviews[]" value="22" / >> > ... > > inputs = []; > > $("#dataTableBody input[id^=selected]:checked").each(function() { > inputs.push(this.name + '=' + escape(this.value)); > }); > > $.ajax({ > type: "POST", > data: inputs.join('&'), > url: "/gateway/excel.php", > success: function(){ > return true; > }, > error: function(XMLHttpRequest, textStatus, errorThrown){ > return false; > } > }); > > In Firebug, I'm getting the data in TSV format, but I'm not being > presented the download dialog within my browser. If this was a > straight file download, I would link directly to it, but the file has > to be built dynamically. Can I set the dataType option in the ajax > call to be "file" or something? What are my options? > > > -- > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.516 / Virus Database: 269.21.4/1312 - Release Date: > 2008-03-04 21:46 > >