473,480 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 43936
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
1799
by: Marcus | last post by:
Hi All, I was wondering if there is a way to ensure that when submitting forms and using POST vars, the page sending the form resides on the same server as the destination page specified in the...
1
3022
by: sarah | last post by:
Hi.. I'm having a problem trying to figure out the best way to process a POST and add items to my database, and hope someone can help me... :) Background: I have a database that I will use to...
5
5323
by: Kit | last post by:
Hi there, I am recoding a website, and I want to add a generic footer to each page, using an included file with PHP snippets. Part of that footer would be a link to validate the page using the...
2
4694
by: Deb M. | last post by:
I am trying to find out how I can use the ASP.net framework yet still post the variables to an external script (not ASPX) after the form has been submitted. So, the ASPX page will still post to...
3
1816
by: Lars Netzel | last post by:
Hello! I have a button, in the click event I have this code: ---------------------------------------------------------------------------- ---------------------------- Response.Write("<script...
2
3495
by: monomaniac21 | last post by:
Hi I know this isnt really a php question but can anyone tell me how you parse post variables to a popup window, here's my code so far, im trying to pass the value entered into a radio button: ...
2
3970
by: Rob Long | last post by:
Hi there Is there any way to access private variables directly from within a priviliged function? I have a situation where the priviliged function's execution context contains variables of the...
2
1814
by: roN | last post by:
Hi, how can I send post variables from out of a php script to another script? I need to send some post var to a third party script, but would like to insert our own php script between the...
5
2097
by: WhatsPHP | last post by:
Hi For some reason, at random posts, the post variables don't get thru to the server. For example, if there is are two text fields: name and email... (I have register_globals on)... When I try...
3
2050
by: Vic Spainhower | last post by:
Hello, I have an HTML table that is being constructed from a MySQL table and displays a form that includes a check box on 1 of the fields on the form for each record. I have included in this PHP...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.