Javascript: Open new window POSTing parameters

openWindowWithPost("http://my.url.address/path", { param1: "value1", param2: "value2", //: }); function openWindowWithPost(url, data) { var form = document.createElement("form"); form.target = "_blank"; form.method = "POST"; form.action = url; form.style.display = "none"; for (var key in data) { var input = document.createElement("input"); input.type = "hidden"; input.name = key; input.value = data[key]; form.appendChild(input); } document.body.appendChild(form); form.submit(); document.body.removeChild(form); }
Open a new window passing parameters via POST.

5 Responses

How do I read the values on the newly opened window?
@Thulasi Ganesh It depends on what you are using on server to receive POST's.
It depends on what you are using on server to receive POST's.
Ok, thanks for the reply.
I have a requirement where I need to invoke Page2(Customer Details) from Page1(Dashboard) using POST since I can't send all parameters in GET. Also, both the pages are already available on the browser as bundle.js, so no form submission is required, because it's single page app.
Do you have any recommendations?
@Thulasi Ganesh Hi Ganesh.
You must have a "POST receptor" at server. Using "fetch" you can do a POST to the server without calling another page. My snippet utility is for "opening" the resulting page while posting parameters. marcopinero@gmail.com, let me know if I can help further.

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.