943,969 Members | Top Members by Rank

Ad:
Dec 6th, 2006
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
evank is offline Offline
14 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript - how to stop/halt/break this loop/script plss
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: change the font/color of the selected text on a web page through javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC