This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Export to xls file - Download file using AJAX  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am looking to export data from a struts application to excel format. Without AJAX, I was able to do it using the response content type & header settings.
When i tried to implement this using AJAX, I am puzzled as how the AJAX response can be made to display the download dialog box on downloading the file from server...

Please help by explaining as how this procedure of exporting a data file to client browser can be done using AJAX.

Thanks,
Ganesh
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not possible. AJAX centers around JavaScript in the browser, which has no concept of files.
 
Ganesh Ramani
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response :-)

I still have a question at this point, with AJAX response as XML.

It is known that AJAX request & response uses XML format, the response data can be obtained as XML using xmlHttp.responseXML.

During an AJAX call, if we write a byte stream in servlet response, can't the xml response be interpreted to any other form? Can this interpretation makes its possible to get different type of content, by customizing the content_type & request headers?

Please explain as how AJAX XML processing happens...

Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a response to an AJAX request I don't think it matters what content type is set. It must be text of some kind, though, since it'll end up in a JavaScript string (so binary content is not possible).
 
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajax was written to handle XML, hence the name of the XMLHttpRequest Object. It was not written to handle other file types.

If you want to download a file, do your form submit to a hidden iframe and do it the way you have always done it with a postback.

Eric
 
Ganesh Ramani
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers
 
Author and ninkuma
Marshal
Posts: 66536
160
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Eric Pascarello:
Ajax was written to handle XML, hence the name of the XMLHttpRequest Object. It was not written to handle other file types.


Though it should be noted that it is perfectly capable of returning other text types other than XML. In fact, XML is is not used all that often in favor of easier to digest formats such as JSON.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a couple of thoughts I had on this...

This first one may or may not be possible as I don't know enough of the XML nuts & bolts. Is it possible to have a multipart mime type in XML as they do in sendmail? I've never seen it done, but don't know enough to know it's impossible.

The second one is similar to Eric's reply. Why not have your filename bundled in an xml tag on the reply and react to it in the callback? Do a transparent submit on a small form to keep the "automatic" look to the user. Of course, you'll have to first store the file on the server and create a reference to it.

I hope this is helpful, it's starting to get late over here .

Aloha,
Doug

-- Nothing is impossible if I'mPossible
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!