wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Can I make a POST request for a new window? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can I make a POST request for a new window?" Watch "Can I make a POST request for a new window?" New topic
Author

Can I make a POST request for a new window?

Joel Jorgensen
Greenhorn

Joined: Oct 13, 2006
Posts: 22
I have an application that gets dynamically generated images from a servlet. Currently the client's Javascript uses a window.open() call with a URL that has a query string appended with the parameters that the server should use to generate the image and the whole thing gets sent as a GET request to the server. However, recent changes to the requirements now require the client side Javascript to create a (potentially lengthy) list of items that it wants to be included in the image, so continuing to use a GET request is not an option.

Is there some way to open a new browser window but have it send a POST request to the server?

If not, is there some way to do this with AJAX (e.g. send an asynchronous POST request, get the response as an 'image/jpeg', open a new browser window, create a new image element within that browser window, and use it to display the image sent from the server)?


Go is to the fountain.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I had to do this for a recent project. You need to make a Ajax request to the server and have it return a url. You than use that URL returned in the responseText in the window.open()

One issue is pop up blockers blocked this.

Another solution is simple:


and another one that I think can be done, but have not tried:


Note the about:blank can be considered a security issue with https

Eric
[ January 04, 2007: Message edited by: Eric Pascarello ]
Joel Jorgensen
Greenhorn

Joined: Oct 13, 2006
Posts: 22
Thanks for the suggestions Eric I ended up using a modification of your first one: I use an AJAX method to post the data to the server, where I then store it in a session attribute. Once that is finished, the client opens the new window, which calls the servlet to generate the image. That servlet gets the data from the session attribute, generates the image, and returns it to the page for display.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I make a POST request for a new window?
 
Similar Threads
session issues with Ctrl-N
Issue in session manegement
Downloading a file from the server.
Which server-side script takes the input from JavaScript in j2ee application
catching page change or browser close