how to access form post or get

Discussion in 'JavaScript' started by buldozerceto, Nov 20, 2007.

  1. #1
    How I can access POST and GET values with javascript
    in PHP is $_GET and $_POST

    but in Javascript
    Searched everywhere. I could not find
     
    buldozerceto, Nov 20, 2007 IP
  2. James McMurray

    James McMurray Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Unless I'm wrong (which is definitely possible) javascript cannot access that data. The data is sent to the server, so PHP can get to it. But as a client-side language javascript is out of luck.
     
    James McMurray, Nov 20, 2007 IP
  3. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #3
    hmm, if you're using PHP in conjunction with JS you can probably asign it to vars

    Ex: var jsVar = '<?php echo $phpVar; ?>';
     
    serialCoder, Nov 20, 2007 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    For variables contained in a <form> you have to access them through the DOM or the form collection whether the form is a GET or POST form. There's a slight exception to this with GET forms.
    Note that there's no way to access POST variables once the form has passed the "onSubmit" event unless the server re-inserts them into the form.

    For GET variables on the querystring, which is where they'll be after a GET <form> has been submitted, you have to parse window.location.href yourself. It will be whatever you see in the address bar of your browser. Firefox gives you direct access to window.location.search which is only the querystring, but Firefox is the only one I know of that does that.
     
    joebert, Nov 21, 2007 IP
  5. James McMurray

    James McMurray Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Also, if your data is in the least bit sensitive, don't use GET. All the login security and enforced strong passwords in the world won't matter if they're up in the address bar. :)
     
    James McMurray, Nov 21, 2007 IP
  6. buldozerceto

    buldozerceto Active Member

    Messages:
    1,137
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    88
    #6
    Thanks for the info.
     
    buldozerceto, Nov 21, 2007 IP