NameSilo

Passing variables from Java Script to PHP

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

freeflow

Established Member
Impact
13
Hi everyone! Can you tell me how to pass variables from Java Script to a PHP File?


This works with a .js file, but how can I make it work with php.

html + .js file

<body>
<h1>Example</h1>
<div id="geo" class="geolocation_data"></div>
<script type="text/JavaScript" src="geo.js"></script>
</body>
</html>



html + php file - How do I have to change the code above to make it work with
the php file below?

<?php

$geo = 'http://maps.google.com/maps/api/geocode/xml?latlng='.htmlentities(htmlspecialchars(strip_tags($_GET['latlng']))).'&sensor=true';
$xml = simplexml_load_file($geo);

...


Thanks for your help.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
Close
you can just echo the code that returns the value of the variable.
 
0
Close
php to javascript is easy since php runs before and you can echo the javascript, if you can make it work on ajax (best solution but a little more complex) then you are on the other side

when I need JS to PHP I usually make a cookie and retreive the data 1 click late or by running a second include with the echo
 
0
Close
dude just use a hidden value in the JS
 
0
Close
<script type="text/javascript">
var myVar = "<?PHP echo $phpVar; ?>";
</script>
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back