get or post?

Discussion in 'Javascript' started by Larry, Jan 25, 2010.

  1. Larry

    Larry Guest

    Is there a way to know if the current page is a result of a get or
    post?
     
    Larry, Jan 25, 2010
    #1
    1. Advertising

  2. Larry wrote:

    > Is there a way to know if the current page is a result of a get or
    > post?


    Yes.


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
     
    Thomas 'PointedEars' Lahn, Jan 25, 2010
    #2
    1. Advertising

  3. Thomas 'PointedEars' Lahn wrote:
    > Larry wrote:
    >
    >> Is there a way to know if the current page is a result of a get or
    >> post?

    >
    > Yes.
    >

    and of course, no.

    Depending on where you are looking at the 'current page' :)

    >
    > PointedEars
     
    The Natural Philosopher, Jan 25, 2010
    #3
  4. Larry

    Scott Sauyet Guest

    On Jan 25, 6:13 am, Thomas 'PointedEars' Lahn <>
    wrote:
    >> Is there a way to know if the current page is a result of a get or
    >> post?

    >
    > Yes.


    No.

    At least, assuming you're discussing doing this from Javascript in a
    web browser. For any POST you perform, the server could send a
    redirect to a GET.

    If you have control on the server-side, you could echo the request
    type into a JS variable; in PHP it might be

    var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"

    Good luck,

    -- Scott
     
    Scott Sauyet, Jan 25, 2010
    #4
  5. Scott Sauyet wrote:

    > Thomas 'PointedEars' Lahn wrote:
    >>> Is there a way to know if the current page is a result of a get or
    >>> post?

    >> Yes.

    ^^^^
    > No.
    >
    > At least, assuming you're discussing doing this from Javascript in a
    > web browser. For any POST you perform, the server could send a
    > redirect to a GET.
    >
    > If you have control on the server-side, you could echo the request
    > type into a JS variable; in PHP it might be
    >
    > var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"


    See, there is a way :)


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
     
    Thomas 'PointedEars' Lahn, Jan 25, 2010
    #5
  6. Thomas 'PointedEars' Lahn wrote:
    > Scott Sauyet wrote:
    >
    >> Thomas 'PointedEars' Lahn wrote:
    >>>> Is there a way to know if the current page is a result of a get or
    >>>> post?
    >>> Yes.

    > ^^^^
    >> No.
    >>
    >> At least, assuming you're discussing doing this from Javascript in a
    >> web browser. For any POST you perform, the server could send a
    >> redirect to a GET.
    >>
    >> If you have control on the server-side, you could echo the request
    >> type into a JS variable; in PHP it might be
    >>
    >> var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"

    >
    > See, there is a way :)
    >
    >

    Right little humourist, is our resident elf...;-)

    > PointedEars
     
    The Natural Philosopher, Jan 25, 2010
    #6
  7. Larry

    Evertjan. Guest

    Thomas 'PointedEars' Lahn wrote on 25 jan 2010 in comp.lang.javascript:
    > Scott Sauyet wrote:
    >
    >> Thomas 'PointedEars' Lahn wrote:
    >>>> Is there a way to know if the current page is a result of a get or
    >>>> post?
    >>> Yes.

    > ^^^^
    >> No.
    >>
    >> At least, assuming you're discussing doing this from Javascript in a
    >> web browser. For any POST you perform, the server could send a
    >> redirect to a GET.
    >>
    >> If you have control on the server-side, you could echo the request
    >> type into a JS variable; in PHP it might be
    >>
    >> var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"

    >
    > See, there is a way :)


    No there is not.

    The new page can never know if the page request is
    1 a result of a bona fide form-get
    or
    2 just from a link contaning an URL with querystring.

    You can never know if the page request is from a
    form-post just if it tests positive a querystring
    as this could be contained in the form post action='...?a=b'.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jan 25, 2010
    #7
  8. Larry

    Scott Sauyet Guest

    On Jan 25, 4:00 pm, "Evertjan." <> wrote:
    > The new page can never know if the page request is
    > 1 a result of a bona fide form-get
    > or
    > 2 just from a link contaning an URL with querystring.


    I'm not sure that is a meaningful distinction. At the HTTP level,
    both are GET requests, so even the server doesn't distinguish this.

    -- Scott
     
    Scott Sauyet, Jan 25, 2010
    #8
  9. Larry

    Evertjan. Guest

    Scott Sauyet wrote on 25 jan 2010 in comp.lang.javascript:

    > On Jan 25, 4:00ÿpm, "Evertjan." <> wrote:
    >> The new page can never know if the page request is
    >> 1 a result of a bona fide form-get
    >> or
    >> 2 just from a link contaning an URL with querystring.

    >
    > I'm not sure that is a meaningful distinction. At the HTTP level,
    > both are GET requests, so even the server doesn't distinguish this.


    No, they could also be POST requests at ther same time.

    If you define a GET request als if without a querystring,
    the whole OQ is meaningless.

    The only interesting Q is if there is POST content
    and if there is querytring content.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jan 25, 2010
    #9
  10. Larry

    Eric Bednarz Guest

    "Evertjan." <> writes:

    > Thomas 'PointedEars' Lahn wrote on 25 jan 2010 in comp.lang.javascript:


    >> Scott Sauyet wrote:


    >>> [OP, ed.]


    >>>>> Is there a way to know if the current page is a result of a get or
    >>>>> post?


    >>> var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"

    >>
    >> See, there is a way :)

    >
    > No there is not.


    I read that as wanting to know the request method, and I would think
    that a HTTP server cannot resolve a resource and send response headers
    without knowing that.

    I wonder what you read.
     
    Eric Bednarz, Jan 26, 2010
    #10
  11. Larry

    Eric Bednarz Guest

    "Evertjan." <> writes:

    > Scott Sauyet wrote on 25 jan 2010 in comp.lang.javascript:
    >
    >> "Evertjan." <> wrote:


    >>> The new page can never know if the page request is
    >>> 1 a result of a bona fide form-get
    >>> or
    >>> 2 just from a link contaning an URL with querystring.

    >>
    >> I'm not sure that is a meaningful distinction. At the HTTP level,
    >> both are GET requests, so even the server doesn't distinguish this.

    >
    > No, they could also be POST requests at ther same time.


    I would like an example of an HTTP request that simultaneously uses the
    HTTP GET and POST methods.
     
    Eric Bednarz, Jan 26, 2010
    #11
  12. Larry

    Erwin Moller Guest

    Eric Bednarz schreef:
    > "Evertjan." <> writes:
    >
    >> Scott Sauyet wrote on 25 jan 2010 in comp.lang.javascript:
    >>
    >>> "Evertjan." <> wrote:

    >
    >>>> The new page can never know if the page request is
    >>>> 1 a result of a bona fide form-get
    >>>> or
    >>>> 2 just from a link contaning an URL with querystring.
    >>> I'm not sure that is a meaningful distinction. At the HTTP level,
    >>> both are GET requests, so even the server doesn't distinguish this.

    >> No, they could also be POST requests at ther same time.

    >
    > I would like an example of an HTTP request that simultaneously uses the
    > HTTP GET and POST methods.


    Here is one:

    <form action="whatever.php?id=12" Method="POST" name="testform">
    Firstname: <input type="text" name="firstname">
    <input type="submit">
    </form>

    Then from PHP (whatever.php):
    -------------------------------
    <pre>
    GET contains:
    <?php
    print_r($_GET);
    ?>
    POST contains:
    <?php
    print_r($_POST);
    ?>
    </pre>
    -------------------------------

    It is a bit weird I admit, but it works just fine.


    Regards,
    Erwin Moller

    --
    "There are two ways of constructing a software design: One way is to
    make it so simple that there are obviously no deficiencies, and the
    other way is to make it so complicated that there are no obvious
    deficiencies. The first method is far more difficult."
    -- C.A.R. Hoare
     
    Erwin Moller, Jan 26, 2010
    #12
  13. Larry

    Scott Sauyet Guest

    On Jan 26, 5:55 am, Erwin Moller
    <> wrote:
    > Eric Bednarz schreef:
    >> I would like an example of an HTTP request that simultaneously uses the
    >> HTTP GET and POST methods.

    >
    > Here is one:
    >
    > <form action="whatever.php?id=12" Method="POST" name="testform">
    > Firstname: <input type="text" name="firstname">
    > <input type="submit">
    > </form>
    > [ ... ]
    > It is a bit weird I admit, but it works just fine.


    Well, this still is an HTTP POST request. PHP interprets the query
    string of the URL as GET variables, but it is not a GET request.

    -- Scott
     
    Scott Sauyet, Jan 26, 2010
    #13
  14. Larry

    Evertjan. Guest

    Eric Bednarz wrote on 26 jan 2010 in comp.lang.javascript:

    >>> See, there is a way :)

    >>
    >> No there is not.


    Here you skip the explanation of the above "no ..."

    > I read that


    my sentence?

    > as wanting to know the request method, and I would think
    > that a HTTP server cannot resolve a resource and send response headers
    > without knowing that.


    What HTTP-server [is there such an animal?]?

    What Resource?

    Why should a server without serverside programming ability [if that is what
    you mean by HTTP-server], do anything with the POST content of the request
    header?

    > and send response headers without knowing that.


    The request querystring has no special request or response headers.

    The POST content is in the request header, not in the response header.

    I think!!!

    > I wonder what you read.


    Where? In the Header?



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jan 26, 2010
    #14
  15. Larry

    Evertjan. Guest

    Scott Sauyet wrote on 26 jan 2010 in comp.lang.javascript:

    > On Jan 26, 5:55ÿam, Erwin Moller
    > <> wrote:
    >> Eric Bednarz schreef:
    >>> I would like an example of an HTTP request that simultaneously uses the
    >>> HTTP GET and POST methods.

    >>
    >> Here is one:
    >>
    >> <form action="whatever.php?id=12" Method="POST" name="testform">
    >> Firstname: <input type="text" name="firstname">
    >> <input type="submit">
    >> </form>
    >> [ ... ]
    >> It is a bit weird I admit, but it works just fine.

    >
    > Well, this still is an HTTP POST request. PHP interprets the query
    > string of the URL as GET variables, but it is not a GET request.


    So we should define a GET request in the OQ sense just as a any request
    that is not a HTTP POST request [disregarding the HEAD request which has no
    clientside coding ability]?

    You could do that, but what would be the use for the OP?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jan 26, 2010
    #15
  16. Larry

    Scott Sauyet Guest

    On Jan 26, 2:16 pm, "Evertjan." <> wrote:
    > Scott Sauyet wrote on 26 jan 2010 in comp.lang.javascript:
    >> On Jan 26, 5:55ÿam, Erwin Moller
    >> Well, this still is an HTTP POST request.  PHP interprets the query
    >> string of the URL as GET variables, but it is not a GET request.

    >
    > So we should define a GET request in the OQ sense just as a any request
    > that is not a HTTP POST request [disregarding the HEAD request which has no
    > clientside coding ability]?


    No, but there is a specific verb given in the HTTP specification that
    is used for each request. If that request responds with a page, there
    is no client-side way from that page to know what verb was used; of
    course additional server-side help can easily be supplied. That's
    what I said in my original response.

    > You could do that, but what would be the use for the OP?


    I don't know what the OP needs, but if it's to know, for instance,
    that the current page is in response to a POST request, I believe that
    this is not possible in general without server-side help.

    -- Scott
     
    Scott Sauyet, Jan 26, 2010
    #16
  17. Larry

    Eric Bednarz Guest

    "Evertjan." <> writes:

    > Eric Bednarz wrote on 26 jan 2010 in comp.lang.javascript:


    >> I read that

    >
    > my sentence?


    The OP’s question:

    | Is there a way to know if the current page is a result of a get or
    | post?

    >> as wanting to know the request method, and I would think
    >> that a HTTP server cannot resolve a resource and send response headers
    >> without knowing that.

    >
    > What HTTP-server


    I don’t know which HTTP server the OP uses. :)

    > What Resource?


    The resource that tentatively wants to know if it is a result of a GET
    or POST request.

    > Why should a server without serverside programming ability [if that is what
    > you mean by HTTP-server],


    By HTTP server I mean a server that services HTTP requests.

    > do anything with the POST content of the request
    > header?


    ¿Que?

    >> and send response headers without knowing that.

    >
    > The request querystring has no special request or response headers.


    I think that this might be a pretty silly discussion.

    > The POST content is in the request header,


    I thought that POST data is send in the message body of the request.

    > not in the response header.


    I should better just have written ‘a response’.

    The request method is stated in the request header, and is hopefully
    accessible by server-side script (e.g. by the already mentioned
    REQUEST_METHOD environment variable). Both response header and message
    body may or may not depend on it.
     
    Eric Bednarz, Jan 26, 2010
    #17
  18. Evertjan. wrote:
    > Thomas 'PointedEars' Lahn wrote on 25 jan 2010 in comp.lang.javascript:
    >> Scott Sauyet wrote:
    >>
    >>> Thomas 'PointedEars' Lahn wrote:
    >>>>> Is there a way to know if the current page is a result of a get or
    >>>>> post?
    >>>> Yes.

    >> ^^^^
    >>> No.
    >>>
    >>> At least, assuming you're discussing doing this from Javascript in a
    >>> web browser. For any POST you perform, the server could send a
    >>> redirect to a GET.
    >>>
    >>> If you have control on the server-side, you could echo the request
    >>> type into a JS variable; in PHP it might be
    >>>
    >>> var httpMethod = "<?php echo $_SERVER['REQUEST_METHOD']; ?>"

    >> See, there is a way :)

    >
    > No there is not.
    >
    > The new page can never know


    anythinmg. new pages are not intelligent, nor even computing engyns

    Straw man. The ELF shot you.
     
    The Natural Philosopher, Jan 27, 2010
    #18
  19. Scott Sauyet wrote:
    > On Jan 25, 4:00 pm, "Evertjan." <> wrote:
    >> The new page can never know if the page request is
    >> 1 a result of a bona fide form-get
    >> or
    >> 2 just from a link contaning an URL with querystring.

    >
    > I'm not sure that is a meaningful distinction. At the HTTP level,
    > both are GET requests, so even the server doesn't distinguish this.
    >


    It does

    > -- Scott
     
    The Natural Philosopher, Jan 27, 2010
    #19
  20. Eric Bednarz wrote:
    > "Evertjan." <> writes:
    >
    >> Scott Sauyet wrote on 25 jan 2010 in comp.lang.javascript:
    >>
    >>> "Evertjan." <> wrote:

    >
    >>>> The new page can never know if the page request is
    >>>> 1 a result of a bona fide form-get
    >>>> or
    >>>> 2 just from a link contaning an URL with querystring.
    >>> I'm not sure that is a meaningful distinction. At the HTTP level,
    >>> both are GET requests, so even the server doesn't distinguish this.

    >> No, they could also be POST requests at ther same time.

    >
    > I would like an example of an HTTP request that simultaneously uses the
    > HTTP GET and POST methods.


    I do it somewhat regularly..

    VERY possible with javascript.
     
    The Natural Philosopher, Jan 27, 2010
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oleg
    Replies:
    0
    Views:
    1,168
  2. Sridhar Hegde
    Replies:
    2
    Views:
    2,525
    Ajeetha Kumari
    Sep 13, 2004
  3. khawar
    Replies:
    2
    Views:
    1,407
    vMike
    Oct 28, 2003
  4. Shiv
    Replies:
    3
    Views:
    823
    John C. Bollinger
    Oct 13, 2003
  5. arnuld
    Replies:
    6
    Views:
    612
    arnuld
    Sep 5, 2007
Loading...

Share This Page