views:

315

answers:

4

Hello All:

I am opening a window and passing set of parameters to it. In this case, I am sending json string. At time, the info is toolarge, and Request-URI Too Large occurs.

window.open('../pssops21/php/createPhonePdf.php?strSelectedItems=' 
   + strSelectedItems + '&strQBNumbers=' + arrQBNumbers, 'mywindow', 
   'resizable=1, scrollbars=1, left=80,top=60, width=650, min-height=400')

Window.open does not have option to post. Jquery ajax only posts info retrieves, results and does not open a new window.

Are there any methods to do this?

Thanks.

A: 

You could open a new window to a temporary page, then POST from that page in the new window using a form filled out by JavaScript in the original page.

SLaks
+2  A: 

Unfortunately this is tricky situation in web applications. The limit on the size of a URI is typically dictated by the browser you are using and the option to POST data is not a standard available. As for doing an Ajax post and then "loading" the results, is typically not supported for security reasons.

A workaround I have used in the past is to make it a two-step process. Basically use Ajax to post your json data to the server. As a response, have the server send back some kind of token to retrieve the stored data. Then, use that token as a parameter to the new window you are opening, who can then retrieve the data.

I know it is a little bit more work to get the data over to your new page, but it does eliminate these size/security restrictions, and is a cross-browser safe.

Mike Clark
A: 

You could use a hidden form that has your destination page as its target. Use hidden fields for your post values, and submit the form using the Javascript submit() method.

I believe this will only work if you're trying to redirect the current window, not open a popup, although there may be a way around that restriction as well.

DanielMason
A: 

Rather than embedding information to pass to the window in the querystring, you can use javascript directly. Using window.opener on the newly opened window, you can access info from the child page:

var selItems = window.opener.strSelectedItems;

Keep in mind that strSelectedItems in this case would need to be globally scoped in the parent page. To keep things clean, I would consider functions on the main page that will return the information the child page needs.

Ryan Brunner
This could work, except that I need in a php.
Natkeeran