question about post/get

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

    #1

    question about post/get

    Hi, all

    When I do as the following, it becomes a GET action to the the server. How
    do I make it as a POST action? That means I don't want the string after "?"
    show on URL bar and, to the server, it can follow POST function to get the
    data passed in. Thank you very much!

    window.open("../../Server.php?"+xs Value, "", zNONHTML_STYLE) ;


    Jack


  • Ivo

    #2
    Re: question about post/get

    "q2005" wrote[color=blue]
    > When I do as the following, it becomes a GET action to the the server.[/color]
    How[color=blue]
    > do I make it as a POST action? That means I don't want the string after[/color]
    "?"[color=blue]
    > show on URL bar and, to the server, it can follow POST function to get[/color]
    the[color=blue]
    > data passed in. Thank you very much!
    >
    > window.open("../../Server.php?"+xs Value, "", zNONHTML_STYLE) ;[/color]

    This is a GET request, yes, but only if javascript is available. Without
    javascript it is nothing.
    If you want to POST something, there is no around using a form. If the
    reliance on javascript is not a problem (but it usually is), this form can
    be built dynamically:
    var f=document.crea teElement('form ');
    document.body.a ppendChild(f);
    f.action='../../Server.php';
    f.method='post' ;
    var i=document.crea teElement('inpu t');
    f.appendChild(i );
    i.type='hidden' ;
    i.name='somenam e';
    i.value=xsValue ;
    f.submit();

    HTH
    --
    Ivo


    Comment

    • q2005

      #3
      Re: question about post/get

      Thanks, Ivo. It's so helpful. By the way, after summit, how do I delete the
      form object? Thanks again!

      Jack
      [color=blue]
      > This is a GET request, yes, but only if javascript is available. Without
      > javascript it is nothing.
      > If you want to POST something, there is no around using a form. If the
      > reliance on javascript is not a problem (but it usually is), this form can
      > be built dynamically:
      > var f=document.crea teElement('form ');
      > document.body.a ppendChild(f);
      > f.action='../../Server.php';
      > f.method='post' ;
      > var i=document.crea teElement('inpu t');
      > f.appendChild(i );
      > i.type='hidden' ;
      > i.name='somenam e';
      > i.value=xsValue ;
      > f.submit();
      >
      > HTH
      > --
      > Ivo
      >
      >[/color]


      Comment

      • Ivo

        #4
        Re: question about post/get

        "q2005" wrote[color=blue][color=green]
        > > This is a GET request, yes, but only if javascript is available. Without
        > > javascript it is nothing.
        > > If you want to POST something, there is no around using a form. If the
        > > reliance on javascript is not a problem (but it usually is), this form[/color][/color]
        can[color=blue][color=green]
        > > be built dynamically:
        > > var f=document.crea teElement('form ');
        > > document.body.a ppendChild(f);
        > > f.action='../../Server.php';
        > > f.method='post' ;
        > > var i=document.crea teElement('inpu t');
        > > f.appendChild(i );
        > > i.type='hidden' ;
        > > i.name='somenam e';
        > > i.value=xsValue ;
        > > f.submit();[/color][/color]
        [color=blue]
        > Thanks, Ivo. It's so helpful. By the way, after summit, how do I delete[/color]
        the[color=blue]
        > form object? Thanks again![/color]

        You don't. The form is submitted, so the whole page is 'deleted' as the
        server responds with a brand new page. Note that the example code provided
        does not test for features before using them. Include
        if(document.cre ateElement) {...} and stuff like that before using it in the
        real world. Also, try to avoid relying on javascript. If you can do it with
        an ordinary form, and it sounds like you can, then do.
        HTH
        --
        Ivo


        Comment

        • q2005

          #5
          Re: question about post/get

          Thanks a lot, Ivo.
          How do I let it be opened in a separate window after submmit?

          Jack


          Comment

          • Ivo

            #6
            Re: question about post/get

            "q2005" aka Jack wrote[color=blue]
            > How do I let it be opened in a separate window after submmit?[/color]

            In standard HTML, you can add a target attribute to the form opening tag and
            it will behave just like the target attribute of <a> tags:

            <form action="..." method="..." target="_blank" >

            Amazing, isn't it?
            In Javascript, to get the same result, you could add this line to the code
            we discussed earlier:

            f.target='_blan k';

            --
            Ivo


            Comment

            • q2005

              #7
              Re: question about post/get

              Thanks very much, Ivo. It works!

              Jack[color=blue]
              >
              > In standard HTML, you can add a target attribute to the form opening tag[/color]
              and[color=blue]
              > it will behave just like the target attribute of <a> tags:
              >
              > <form action="..." method="..." target="_blank" >
              >
              > Amazing, isn't it?
              > In Javascript, to get the same result, you could add this line to the code
              > we discussed earlier:
              >
              > f.target='_blan k';
              >
              > --
              > Ivo
              >
              >[/color]


              Comment

              • q2005

                #8
                Re: question about post/get

                Hi, Ivo
                I tried this script and found "i.type='hidden ';" won't work. I changed to
                "i.type='text'; " , it works. But it will show on the original page.

                Jack

                "Ivo" <no@thank.you > wrote in message
                news:41996241$0 $45963$a344fe98 @news.wanadoo.n l...[color=blue]
                > "q2005" wrote[color=green]
                > > When I do as the following, it becomes a GET action to the the server.[/color]
                > How[color=green]
                > > do I make it as a POST action? That means I don't want the string after[/color]
                > "?"[color=green]
                > > show on URL bar and, to the server, it can follow POST function to get[/color]
                > the[color=green]
                > > data passed in. Thank you very much!
                > >
                > > window.open("../../Server.php?"+xs Value, "", zNONHTML_STYLE) ;[/color]
                >
                > This is a GET request, yes, but only if javascript is available. Without
                > javascript it is nothing.
                > If you want to POST something, there is no around using a form. If the
                > reliance on javascript is not a problem (but it usually is), this form can
                > be built dynamically:
                > var f=document.crea teElement('form ');
                > document.body.a ppendChild(f);
                > f.action='../../Server.php';
                > f.method='post' ;
                > var i=document.crea teElement('inpu t');
                > f.appendChild(i );
                > i.type='hidden' ;
                > i.name='somenam e';
                > i.value=xsValue ;
                > f.submit();
                >
                > HTH
                > --
                > Ivo
                >
                >[/color]


                Comment

                • Michael Winter

                  #9
                  Re: question about post/get

                  On Tue, 16 Nov 2004 20:11:56 +1000, q2005 <q2005@tpg.com. au> wrote:
                  [color=blue]
                  > I tried this script and found "i.type='hidden ';" won't work.[/color]

                  I assume you mean with IE?

                  According to Microsoft, the type attribute "is read[-many]/write-once, but
                  only when an input element is created with the createElement method and
                  before it is added to the document."

                  To be safe, the appendChild (or similar, like insertBefore) should be the
                  very last operation with a dynamically-created element. Set all of the
                  properties, and only then should said element be added.
                  [color=blue]
                  > I changed to "i.type='text'; " , it works.[/color]

                  Actually, I doubt that. The assignment will still probably fail, but
                  because text is the default type, it appears as though it succeeded.

                  [snip]

                  Mike


                  Please don't top-post.

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

                  Comment

                  • q2005

                    #10
                    Re: question about post/get

                    Thanks, Michael.
                    [color=blue][color=green]
                    > > I tried this script and found "i.type='hidden ';" won't work.[/color]
                    >
                    > I assume you mean with IE?[/color]
                    Yes, I mean with IE.[color=blue]
                    >
                    > According to Microsoft, the type attribute "is read[-many]/write-once, but
                    > only when an input element is created with the createElement method and
                    > before it is added to the document."
                    >
                    > To be safe, the appendChild (or similar, like insertBefore) should be the
                    > very last operation with a dynamically-created element. Set all of the
                    > properties, and only then should said element be added.[/color]

                    After put the appendChild() at the very last, there is no more error!

                    Jack


                    Comment

                    • RobB

                      #11
                      Re: question about post/get

                      "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message news:<opshjy49n qx13kvk@atlanti s>...[color=blue]
                      > On Tue, 16 Nov 2004 20:11:56 +1000, q2005 <q2005@tpg.com. au> wrote:
                      >[color=green]
                      > > I tried this script and found "i.type='hidden ';" won't work.[/color]
                      >
                      > I assume you mean with IE?
                      >
                      > According to Microsoft, the type attribute "is read[-many]/write-once, but
                      > only when an input element is created with the createElement method and
                      > before it is added to the document."
                      >
                      > To be safe, the appendChild (or similar, like insertBefore) should be the
                      > very last operation with a dynamically-created element. Set all of the
                      > properties, and only then should said element be added.
                      >[color=green]
                      > > I changed to "i.type='text'; " , it works.[/color]
                      >
                      > Actually, I doubt that. The assignment will still probably fail, but
                      > because text is the default type, it appears as though it succeeded.
                      >
                      > [snip]
                      >
                      > Mike
                      >
                      >
                      > Please don't top-post.[/color]


                      "Ivo" wrote:
                      [color=blue]
                      > If you want to POST something, there is no around using a form.[/color]

                      Might want to read this:


                      Also, the best way to handle the opening of the form action in a new
                      window is by 1) setting HTML form target to a specific name string and
                      2) calling a function onsubmit which opens a configured window,
                      setting its name (2nd argument to open()) to the target name. Might as
                      well get the window you want.

                      Comment

                      • q2005

                        #12
                        Re: question about post/get

                        Thanks, RobB.

                        Can you give me an example code about "the best way to handle the opening of
                        the form action in a new window". Thank you very much!


                        Jack
                        "RobB" <ferndoc9@hotma il.com> wrote in message
                        news:ab354593.0 411161139.592c0 9b9@posting.goo gle.com...[color=blue]
                        > "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message[/color]
                        news:<opshjy49n qx13kvk@atlanti s>...[color=blue][color=green]
                        > > On Tue, 16 Nov 2004 20:11:56 +1000, q2005 <q2005@tpg.com. au> wrote:
                        > >[color=darkred]
                        > > > I tried this script and found "i.type='hidden ';" won't work.[/color]
                        > >
                        > > I assume you mean with IE?
                        > >
                        > > According to Microsoft, the type attribute "is read[-many]/write-once,[/color][/color]
                        but[color=blue][color=green]
                        > > only when an input element is created with the createElement method and
                        > > before it is added to the document."
                        > >
                        > > To be safe, the appendChild (or similar, like insertBefore) should be[/color][/color]
                        the[color=blue][color=green]
                        > > very last operation with a dynamically-created element. Set all of the
                        > > properties, and only then should said element be added.
                        > >[color=darkred]
                        > > > I changed to "i.type='text'; " , it works.[/color]
                        > >
                        > > Actually, I doubt that. The assignment will still probably fail, but
                        > > because text is the default type, it appears as though it succeeded.
                        > >
                        > > [snip]
                        > >
                        > > Mike
                        > >
                        > >
                        > > Please don't top-post.[/color]
                        >
                        >
                        > "Ivo" wrote:
                        >[color=green]
                        > > If you want to POST something, there is no around using a form.[/color]
                        >
                        > Might want to read this:
                        > http://developer.apple.com/internet/...mlhttpreq.html
                        >
                        > Also, the best way to handle the opening of the form action in a new
                        > window is by 1) setting HTML form target to a specific name string and
                        > 2) calling a function onsubmit which opens a configured window,
                        > setting its name (2nd argument to open()) to the target name. Might as
                        > well get the window you want.[/color]


                        Comment

                        • Michael Winter

                          #13
                          Re: question about post/get

                          On Thu, 18 Nov 2004 00:48:30 +1000, q2005 <q2005@tpg.com. au> wrote:
                          [color=blue]
                          > Can you give me an example code about "the best way to handle the
                          > opening of the form action in a new window". Thank you very much![/color]

                          It's in the FAQ. The usual link is <URL:http://jibbering.com/faq/>,
                          however I can't access it at the moment. In the meantime, you can use an
                          out-of-date copy, courtesy of the Wayback Machine
                          (<URL:http://www.archive.org/web/web.php>):

                          <URL:http://web.archive.org/web/20040202174454/http://www.jibbering.c om/faq/>

                          [snip]

                          Mike


                          Don't top-post!

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

                          Comment

                          • RobB

                            #14
                            Re: question about post/get

                            "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message news:<opshl6oen qx13kvk@atlanti s>...[color=blue]
                            > On Thu, 18 Nov 2004 00:48:30 +1000, q2005 <q2005@tpg.com. au> wrote:
                            >[color=green]
                            > > Can you give me an example code about "the best way to handle the
                            > > opening of the form action in a new window". Thank you very much![/color]
                            >
                            > It's in the FAQ. The usual link is <URL:http://jibbering.com/faq/>,
                            > however I can't access it at the moment. In the meantime, you can use an
                            > out-of-date copy, courtesy of the Wayback Machine
                            > (<URL:http://www.archive.org/web/web.php>):
                            >
                            > <URL:http://web.archive.org/web/20040202174454/http://www.jibbering.c om/faq/>
                            >
                            > [snip]
                            >
                            > Mike
                            >
                            >
                            > Don't top-post![/color]

                            Dug this out of the vault, hope it helps. Some bits are demo-only.

                            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                            <html xmlns="http://www/w3/org/TR/xhtml1">
                            <head>
                            <title>untitled </title>
                            <script type="text/javascript">
                            //<![CDATA[

                            function dummy(v)
                            {
                            return '<h4>' + v + '</h4>';
                            }

                            function handle_submit(f )
                            {
                            if (document.getEl ementById('w'). checked)
                            {
                            f.target = 'formpop';
                            f.action = 'javascript:ope ner.dummy(opene r.document.form s[0].foo.value)';
                            //demo only
                            var w = 300;
                            var h = 180;
                            var l = (screen.availWi dth - w) * .5;
                            var t = (screen.availHe ight - h) * .5;
                            var features = 'width='+w+',he ight='+h+',left ='+l+',top='+t+ ',status,scroll bars,resizable' ;
                            formpop = open('about:bla nk', 'formpop', features);
                            formpop.focus() ;
                            return true;
                            }
                            else
                            {
                            f.target = '_self';
                            f.action = 'javascript:dum my(document.for ms[0].foo.value)'; //ditto
                            }
                            }

                            // ]]>
                            </script>
                            </head>
                            <body>
                            <form action="javascr ipt:dummy(docum ent.forms[0].foo.value)"
                            onsubmit="retur n handle_submit(t his)">
                            <input id="w" type="checkbox" /> open in new window?<br /><br />
                            <input type="text" name="foo" value="...enter something here" />
                            <input type="submit" value="done" />
                            </form>
                            </body>
                            </html>

                            Comment

                            • q2005

                              #15
                              Re: question about post/get

                              Thanks RobB.
                              On this example, when open in a new window, sometimes it won't work. The IE
                              browser said "this page can not displayed". The most times, it works.
                              questions:
                              1. Why on open new window needs to return true while on _self doesn't need?
                              2. Since on handle_submit() , it will change the action, is the "action=" in
                              the form a dummy one? Or it should have?
                              3. How can the action can be executed either on the new page or the original
                              page? Does it depend on target?

                              Jack
                              [color=blue]
                              >
                              > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                              > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
                              > <html xmlns="http://www/w3/org/TR/xhtml1">
                              > <head>
                              > <title>untitled </title>
                              > <script type="text/javascript">
                              > //<![CDATA[
                              >
                              > function dummy(v)
                              > {
                              > return '<h4>' + v + '</h4>';
                              > }
                              >
                              > function handle_submit(f )
                              > {
                              > if (document.getEl ementById('w'). checked)
                              > {
                              > f.target = 'formpop';
                              > f.action = 'javascript:ope ner.dummy(opene r.document.form s[0].foo.value)';
                              > //demo only
                              > var w = 300;
                              > var h = 180;
                              > var l = (screen.availWi dth - w) * .5;
                              > var t = (screen.availHe ight - h) * .5;
                              > var features =[/color]
                              'width='+w+',he ight='+h+',left ='+l+',top='+t+ ',status,scroll bars,resizable' ;[color=blue]
                              > formpop = open('about:bla nk', 'formpop', features);
                              > formpop.focus() ;
                              > return true;
                              > }
                              > else
                              > {
                              > f.target = '_self';
                              > f.action = 'javascript:dum my(document.for ms[0].foo.value)'; //ditto
                              > }
                              > }
                              >
                              > // ]]>
                              > </script>
                              > </head>
                              > <body>
                              > <form action="javascr ipt:dummy(docum ent.forms[0].foo.value)"
                              > onsubmit="retur n handle_submit(t his)">
                              > <input id="w" type="checkbox" /> open in new window?<br /><br />
                              > <input type="text" name="foo" value="...enter something here" />
                              > <input type="submit" value="done" />
                              > </form>
                              > </body>
                              > </html>[/color]


                              Comment

                              Working...