• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to export to Excel using Ajax

 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I must be missing some fundamental difference between the way a HTTP GET works and the way the jQuery .ajax() get works.

This servlet exports a table of information to Excel and it works fine when this I use this URL:
"localhost:8080/mfgweb/AbsenteeismExcelExport?startdate=20130601&enddate=20130615&numrecords=25"


So why doesn't it work when I use this jQuery code?

By my reasoning I shouldn't have to do anything with the results in the javascript code because the servlet sends the results directly to the PrintWriter. I can see the GET request in Firebug and the response but I never get the dialog box to open or save the Excel file.

What am I missing?

[EDIT] I just found this thread. It seems I'm trying to do the impossible. Back to the drawing board.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bingo. Ajax doesn't do files.
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still puzzled though. My understanding is that Ajax is just a way of forming and sending a request. Once it's sent, that's it. The server forms the response and sends it back to the browser. Is there something unique, such as a header, in the response that says "this response is intended for the Javascript engine, not the HTTP rendering engine"? There must be some way that the browser knows the difference.

I know I'm getting into technical details that aren't really pertinent, but I'm one of those people that has to understand how everything works. Maybe there is a technical specification on Javascript that I need to read?
 
author
Posts: 297
5
Android Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the browser couldn't tell the difference AJAX wouldn't work, because each response received would just replace the loaded page. If you want to download a file set window.location.href to the download URL and ensure the Content-disposition: attachment header is set at the server side. If you want to guarantee the current page is not replace you cold try dynamically creating an iframe and setting the src on that.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For general understand, take a look at the datatype section of the Ajax jQuery page. It lists the types that can be returned.

Excel is different. It's not text. It's a file. Even your browser doesn't know how to "render" a file. It simply defers to the file system. If Ajax were allowed to download files, you could write a web page that would randomly try to have your machine open downloaded files while you are trying to work. Not good.
reply
    Bookmark Topic Watch Topic
  • New Topic