How to similate HTTP POST request by JavaScript?

R

reneeccwest

How can I simulate HTTP post request by JavaScript?

When I select from <SELECT> combo box. onClick will call JavaScript
function.
I want this function to send HTTP POST request with the selected index of
the combo box.
To do this, somehow the function must simulate HTTP POST request.

Thanks in advance.
 
E

Evertjan.

Richard Hockey wrote on 07 jul 2003 in comp.lang.javascript:
I'm not sure you can 'simulate' a HTTP post request, but you can
submit a form using javascript to set the method, and to execute from
submission (you can also set the action and target window):

document.forms['myform'].method='post';
document.forms['myform'].action='process.php';
document.froms['myform'].target='_self';
document.forms['myform'].submit();

You are right.

It is not simulating a post http-request,

but simulating a classical HTTP-only post request.
 
M

Martin Honnen

reneeccwest said:
How can I simulate HTTP post request by JavaScript?

When I select from <SELECT> combo box. onClick will call JavaScript
function.
I want this function to send HTTP POST request with the selected index of
the combo box.
To do this, somehow the function must simulate HTTP POST request.

Why don't you use HTML?
<form action="whatever.php" method="POST">
<select name="selectName">
<option>...</option>
<option>...</option>
...
</select>
<input type="submit">
</form>

The browser will send a HTTP POST request when the submit button is
clicked/pressed without needing any script.
 
S

Stuart Palmer

<form name="MyForm" action="nextpage.asp" method="POST">
<select name="selectName" onChange="document.MyForm.submit">
<option>make a selection</option>
<option value = "one">one</option>
<option value = "two">two</option>
...
</select>
<input type="submit">
</form>


try something like this. Onclick is wrong because as soon as you click it
would send, without you chnaging anything.

Keep a submit button available for non JS users.

Does that help? If not, let us see some code and tell us exactly what you
want it to do.

Stu
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top