Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I make a POST request for a new window?

 
Joel Jorgensen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic