Skip to main content

Form post with URL paramters (after question mark)

Posted by staufferjames on January 23, 2008 at 12:17 PM PST

I had a URL that I wanted to POST with JavaScript so a made a

        <form name="doForm" action="" method="post">
        </form>

and used JavaScript to set action and call submit. But Tomcat showed the request as a GET (I.E. 7 is my browser). I found that adding a dummy form input fixed the problem:

        <form name="doForm" action="" method="post">
            <input type="hidden" name="blah" value="blah"/><!-- need at least 1 input or the form uses method="get" even when "post" is specified. -->
        </form>
Related Topics >>

Comments

You can POST without a hidden input so I don't see how the hidden input has any impact.

Changing POSTs to GETs definitely wouldn't be helpful. The server may implement each differently and the meaning of POST and GET doesn't allow that. I have written servlets that implement POST and GET different.

Actually, I think it may be the fact that the input is hidden that gets you the POST. I have found that IE will very helpfully change POSTs to GETs if you only have a few inputs (although I haven't tried it on IE7).