#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    1
    Rep Power
    0
    Any discussion I see of <form method=get> vs. <form method=post> assumes the POSTed data will go to a cgi-perl script. I want to read that data in javascript, but can't figure out the js equivalent of a perl's "READ stdin" to get to the data. Any help appreciated

    ------------------
    burro = donkey. burrow = hole in the ground. some people don't know the difference.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    81
    Rep Power
    15
    I'm going to assume you've appended the data to a URL which also brings the user to a new page.

    The URL of this new page is accessed by the read-only property document.url Seems to me you can assign this to a string variable and read the data with the appropriate String and/or RegExp objects.

    Russ

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by rorwell:
    Any discussion I see of <form method=get> vs. <form method=post> assumes the POSTed data will go to a cgi-perl script. I want to read that data in javascript, but can't figure out the js equivalent of a perl's "READ stdin" to get to the data. Any help appreciated

    [/quote]

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    Leeds, UK
    Posts
    171
    Rep Power
    13
    but your method uses GET variables not POST if the data is appended to the url. The problem with this is that a user can just change the values of the data too easily eg. in a shopping cart system.

    i'd be interested to know if it's possibel to read POSTed variables in javascript, but i suspect it ain't possible

    Emily
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    POST and PUT are for sending data from the browser to the server, so no, you're not going to be able to get them back from the server using javascript
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Corvallis, OR
    Posts
    2
    Rep Power
    0

    Maybe try cookies


    Depending on how much data you're trying to pass along, you might be able to store it in a cookie.

    This is an idea a coworker of mine came up with for dealing with a multi-page form on a site that doesn't have PHP. I'll be the one to implement it, though.

    We want to send along just a single, small <textarea> from one page to the next. Shouldn't be too difficult and a session cookie will work just fine.

    Will need to write a function activated onSubmit to find the textarea's value and copy it to the cookie. Then a script in the page that is the form's action will read the cookie and write its value into the textarea.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    India
    Posts
    3
    Rep Power
    0

    Question


    There are alternate methods to retrieve/read/parse POSTed data.

    But what if I've no control over the submitted data (via POST method) and I want to parse this HTTP header that I'm getting from some remote server, using Javascript (or any other client side method)?

    I know that it is only possible using some server side scripting like ASP/JSP/PHP etc. But is it not possible using JS?

    It is also possible using Macromedia Flash, but again these two servers (one sending me the POSTed data and other on which I'm reading that data) have to be the same. Again user should have Flash plug-in installed on his PC. Chances of having Flash plug-in are 90% but what about 10%?

    So please please tell me if there is any client side method? My hopes are 0.05%
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Corvallis, OR
    Posts
    2
    Rep Power
    0
    Deepakpat,

    It's unclear from your message who's talking to whom. Normally, a client (browser) POSTs a form to a server which replies with a HTML document.

    You seem to be thinking that the target of a POST is another browser (client) rather than a server. Indeed, a POST almost always results in receiving a new document, but it would be a misconception. The document the server sends back to the client after POST may or may not have anything to do with the POSTed data. It's entirely dependent on the target of the POST. If you post to a static page (form action="do_nothing.htm"), for example, the POST data (and GET parameters, for that matter) would simply be disregarded. They would not somehow magically be incorporated into the server's response.

    (I suppose you could find some way to run some flavor of JavaScript on the server side. But I think you'll find life much easier in PHP or Perl which are designed for such things.)

    JavaScript in a browser (client-side) is almost entirely dependent on the document in which it exists. It has access to the document model (including any scripts in the document), the URL (including any GET parameters), and cookies.

    JS does not -- at least not in any browser I know of -- retain access to the POST data that may have been sent to obtain the current page. Nor does it have access to the complete header (parameters like keep-alive, status code, etc.).

    Remember that client-side JS doesn't begin to execute until the browser is receiving a document. This document is generated by the server. The server generates its response (the document) after receiving the (complete) query, including any POST data. So to the degree that there would be any stdin on the client side (which there isn't so far as JS is concerned... just events caused by user interaction with the document or scripts), it would be receiving the server's output (HTML document), not the previous client request (POST data).

    Dave
  14. #8
  15. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, you can code ASP pages using Javascript, so I suppose it's *technically* possible .

    corecomm is right, though. A browser has absolutely no access to POST parameters after a request has been sent. They are not sent back by in the response unless the server-side application has been coded to include them in the returned html. In fact, POST data is to an HTTP request what HTML data is to an HTTP response.

    Flash will have the same problem since it runs on the client. Only the server sees the POST data.

Similar Threads

  1. javascript loading xml data for parameter
    By wozoi in forum JavaScript Development
    Replies: 9
    Last Post: June 17th, 2003, 04:16 AM
  2. read from a formated data file
    By CplusQ in forum C Programming
    Replies: 3
    Last Post: October 29th, 2002, 08:56 AM
  3. Using LWP::UserAgent to post and receive data
    By RandyL712 in forum Perl Programming
    Replies: 3
    Last Post: February 28th, 2002, 04:33 PM
  4. Replies: 5
    Last Post: November 11th, 2001, 09:12 AM
  5. Disregarding POST data after it is used once
    By spackbace in forum PHP Development
    Replies: 6
    Last Post: October 19th, 2001, 09:50 PM

IMN logo majestic logo threadwatch logo seochat tools logo