simulate a POST ACTION with javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • q2005

    #1

    simulate a POST ACTION with javascript

    Hi, all

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

    Jack


  • Evertjan.

    #2
    Re: simulate a POST ACTION with javascript

    q2005 wrote on 28 okt 2004 in comp.lang.javas cript:
    [color=blue]
    > Is that possible I can do
    > window.open("ht tp://xserver1/app/typ/test/tesServer.php?a aa=111&bbb=222
    > &ccc= 333","","") to simulate a POST ACTION with a form rather than a
    > GET ACTION?
    >[/color]

    <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.getEle mentById("f").s ubmit()
    ....

    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

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)

    Comment

    • Fox

      #3
      Re: simulate a POST ACTION with javascript

      q2005 wrote:[color=blue]
      > Hi, all
      >
      > Is that possible I can do
      > window.open("ht tp://xserver1/app/typ/test/tesServer.php?a aa=111&bbb=222& ccc=
      > 333","","") to simulate a POST ACTION with a form rather than a GET ACTION?
      >
      > Jack
      >
      >[/color]

      function
      handleSubmit(fo rmRef)
      {
      window.open("", "formTargetWind ow");

      formRef.target = "formTargetWind ow";
      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.xx x" method=post target=formTarg etWindow>

      (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:


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

      Fox
      ************

      Comment

      • Michael Winter

        #4
        Re: simulate a POST ACTION with javascript

        On Thu, 28 Oct 2004 17:29:05 +1000, q2005 <q2005@tpg.com. au> wrote:
        [color=blue]
        > Is that possible I can [use a query string] to simulate a POST ACTION
        > with a form rather than a GET ACTION?[/color]

        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.

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        Working...