This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Export to xls file - Download file using AJAX

 
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: 43016
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: 43016
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
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
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic