simulate a POST ACTION with javascript

E

Evertjan.

q2005 wrote on 28 okt 2004 in comp.lang.javascript:
Is that possible I can do
window.open("http://xserver1/app/typ/test/tesServer.php?aaa=111&bbb=222
&ccc= 333","","") to simulate a POST ACTION with a form rather than a
GET ACTION?

<form id=f method=post target="_blank"
action="http://xserver1/app/typ/test/tesServer.php">
<input type=hidden name=aaa value="111"
<input type=hidden name=bbb value="222"
<input type=hidden name=ccc value="333"
</form>

<script ...>
document.getElementById("f").submit()
....

not tested

==========

Or you do the same targetting
a previously window.open()ed and named window.

==========

Or you can define the whole form in DOM
 
F

Fox

q2005 said:
Hi, all

Is that possible I can do
window.open("http://xserver1/app/typ/test/tesServer.php?aaa=111&bbb=222&ccc=
333","","") to simulate a POST ACTION with a form rather than a GET ACTION?

Jack

function
handleSubmit(formRef)
{
window.open("","formTargetWindow");

formRef.target = "formTargetWindow";
formRef.method = "post";
formRef.action = "http://xserver1/app/typ/test/tesServer.php";

formRef.submit();

return false;
}

There's no reason why you need javascript for this (unless you need to
customize the window):

<form action = "formURL.xxx" method=post target=formTargetWindow>

(just give the window any name you want and post the form to it -- it's
probably a "safer" popup because I don't believe these are suppressed by
popup blockers [could be wrong tho])


js demo in action:
http://site-creations.com/demo/postform2win.htm

all the action script does is var_dump($_POST) wrapped in xmp tags.

Fox
************
 
M

Michael Winter

Is that possible I can [use a query string] to simulate a POST ACTION
with a form rather than a GET ACTION?

Generally, no. If a server-side document expects POST data, it will
generally use methods that obtain *only* POST data.

The only[1] way to submit POST data is via a form.

Mike


[1] Certain hosts may provide other ways, but you can't rely on them on
the Web.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top