Interpret HTTP (Content-Disposition) headers from an XMLHTTP object?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Dec 2006
Posts: 14
Reputation: evank is an unknown quantity at this point 
Solved Threads: 0
evank's Avatar
evank evank is offline Offline
Newbie Poster

Interpret HTTP (Content-Disposition) headers from an XMLHTTP object?

 
0
  #1
Dec 6th, 2006
I'm trying to implement an AJAX solution for exporting tabular data on a page in certain formats, and i've determined that the best way to do this (for my purposes) is to grab the innerHTML of a table, send it off to a server-side script for processing into alternate formats, and then returning the response with appropriate Content-Type and Content-Disposition headers. The issue I'm having is how exactly to get the browser to interpret said headers.

For example, I send the table's innerHTML in a POST request to a server-side script (via an XMLHTTP object):
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. xmlhttp.open("POST", "process.cgi", true);
  2. xmlhttp.onreadystatechange=function() {
  3. if (xmlhttp.readyState==4) {
  4. // do what we need to do
  5. }
  6. }
  7. xmlhttp.send('exportdata='+escape(dataTable.innerHTML));
If someone directly requests the server-side script (ie: through a form), it sends appropriate headers so the user is prompted by the browser to download the file. For example, exporting to an Excel spreadsheet, it sends:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. Content-Type: application/vnd.ms-excel
  2. Content-Disposition: attachment; filename="1165420852.xls"
My problem is, I don't know how to get the browser to interpret those headers coming from an XMLHTTP object.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4015 | Replies: 0
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC