/    Sign up×
Community /Pin to ProfileBookmark

AJAX – passing variable value through several scripts with GET

I have a PHP script that has to pass the value of a variable, call it $name, to a second PHP script using GET. This second PHP script calls a function in a separate .js file. That function also has to know the value of $name, because it calls a third PHP script, again using GET, and must transfer the value of $name to the third script. The third script uses $name to find the right .txt file, open it up, and send what it finds in there back to the second script.

I know how to transfer variable values between the first two PHP scripts using “?name=$name” at the end of the URL, but how do I tell the function in the .js file what the variable value is, so that it can transfer it to the third PHP script? And do I have to? Either way, how I do put the variable in at the end of the url that the javascript function uses to call the third PHP script? PHP variables must have a “$” in front of them, but javascript variables don’t. Would the javascript know what to do with “$name?”.

Before I try a dozen different things at random, I thought I’d see if anyone knows the answer.

Thanks in advance.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Mega69Jun 03.2007 — The simpler way to do this is by dinamically generating the js code:

The second page .php
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
name=&lt;?php print($name); ?&gt;
//Do whatever you want with name
&lt;/script&gt;
×

Success!

Help @rgrne spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...