[Javascript] JavaScript to PHP variable transfer
Roger Roelofs
rer at datacompusa.com
Fri Aug 22 00:01:30 CDT 2003
Dave,
Sorry, I'm still confused. The only way I know of, based on the http
protocol, for javascript to send data to a php script is via a GET or
POST, ( or I suppose a HEAD ) which may or may not contain a cookie.
On Thursday, Aug 21, 2003, at 16:37 America/Detroit, David Lovering
wrote:
> Actually, you are quite close to the mark --
>
> Most of the present client/server communication is done by way of the
> embedded IFRAME constructs
> which contain PHP scripts
Technically they contain the 'output' of a php script. Anyway, why not
have a hidden form on your main page with 1 hidden field. Fill that
field with the data you want and submit it. In the case of creating or
changing php session variables (or database records), the field
contents could look like
s2StateCode:MI
s31CityName:Detroit
....
Then have the form post to a generic php script that parses the field
like so
<?php
session_register();
$aData = split($_POST['data'], "\n"); // this is off the top of my
head, not tested.
for ( $i = 0; $i < length($data); $i++ ) {
$thisVar = split($aData[$i], ":");
$_SESSION[$thisVar[0]] = $thisVar[1];
}
?>
Obviously, real life is more complicated than that sample code, but I
hope it gives you food for thought.
> Considering that POST, GET,
> PUT, and cookies are all vigorously disabled,
If that is true, the server can't be properly called a http (web)
server at all. It couldn't even handle simple page requests.
> The real problem is not getting PHP to talk to JavaScript (that is
> easy!),
> but rather the reverse. Short
> of using JavaScript to "invoke" a piece of PHP script as per the "src="
> destination inside a frame, ...
The only other options I can think of, have already been mentioned i.e.
java with sockets and xml, and in fact most web services protocols
layer on top of http, so GET and/or POST are required there as well.
I feel like I'm not correctly understanding your situation, because I
feel like I'm telling you stuff you already know. A sample of what
you're trying to do would be most useful. Not real data, or even the
real forms, just a page with the same kinds of elements and
interactions would help me brainstorm. If you don't have a public
server for this, I could host some test pages for you.
Roger,
Roger Roelofs
Datacomp Appraisal Services
More information about the Javascript
mailing list