469,568 Members | 1,463 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Access $_POST variables from Javascript?

I know there isn't any $_POST array in Javascript, it exists on the server
side accessible from PHP and other server side scripting languages. But I
knew it would let you know specifically what data I'm after.

Is there any way to get the data that is POSTED to a web page from
client-side Javascript? Or does only the server get access to it?

I can get access to the URL/href data from the "search" property, but that's
because it's part of the URL. What about POST'ed data?

Thanks.
Aug 21 '05 #1
3 43712
Robert Oschler wrote:
I know there isn't any $_POST array in Javascript, it exists on the server
side accessible from PHP and other server side scripting languages. But I
knew it would let you know specifically what data I'm after.

Is there any way to get the data that is POSTED to a web page from
client-side Javascript?
No, the data isn't posted to the web page, it's posted to the server,
which typically returns a web page (or other resource) in response.
Or does only the server get access to it?
That's correct.
I can get access to the URL/href data from the "search" property, but that's
because it's part of the URL. What about POST'ed data?


No, unless that data is output by the server somewhere into the
document, in which case you could access it through the DOM.

--
Lachlan Hunt
http://lachy.id.au/
http://GetFirefox.com/ Rediscover the Web
http://GetThunderbird.com/ Reclaim your Inbox
Aug 21 '05 #2


Robert Oschler wrote:
I know there isn't any $_POST array in Javascript, it exists on the server
side accessible from PHP and other server side scripting languages. But I
knew it would let you know specifically what data I'm after.
If data is posted to the server and JavaScript is used on the server
(for instance in a framework like ASP) then on the server of course the
posted data is exposed to JavaScript e.g. with
Request.Form
in ASP.
Is there any way to get the data that is POSTED to a web page from
client-side Javascript? Or does only the server get access to it?


A HTTP client can make a HTTP POST request sending some data to a HTTP
server and then that data can be processed on the server, if you have
PHP on the server then you can do it with PHP, but if you have
JavaScript on the server then you can do it with JavaScript for
instance. Data does not get POSTed to a web page as such, indeed if you
make a HTTP POST request to a static resource on a HTTP server then you
usually get an error.
As for client-side JavaScript accessing POST data when a from is
submitted (e.g. when for instance the POST request is initiated) then
client-side script in the onsubmit handler can of course use the
client-side DOM to read out any form data but you are reading out the
form controls in the DOM and not a data structure the browser exposes of
data it is going to post. And when your onsubmit handler is done (and
returns true) then the browser makes the HTTP request and at that stage
script in the HTML document certainly has no access to the POSTed data.
And script in the next HTML document the server sends as the response to
the posted data again has no access to the posted data unless (as
already pointed out) of course the server-side script tries to pass on
the data to script.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 21 '05 #3
"Robert Oschler" <no************@nospam.com> wrote in ...
I know there isn't any $_POST array in Javascript, it exists on the server
side accessible from PHP and other server side scripting languages. But I
knew it would let you know specifically what data I'm after.

Is there any way to get the data that is POSTED to a web page from
client-side Javascript? Or does only the server get access to it?

I can get access to the URL/href data from the "search" property, but that's because it's part of the URL. What about POST'ed data?


You can read $_GET from the URL!

For posted variables you have to write the PHP variables to Javascript
variables.

<script>
<? php echo "var1 = " . $_POST("var1"); ?>

</script>

Herc

Aug 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Marcus | last post: by
2 posts views Thread by Deb M. | last post: by
3 posts views Thread by Lars Netzel | last post: by
2 posts views Thread by monomaniac21 | last post: by
2 posts views Thread by roN | last post: by
5 posts views Thread by WhatsPHP | last post: by
3 posts views Thread by Vic Spainhower | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.