accessing concatinated javascript variables in php
i want to access my concatenated javascript variables in php here is my code its through ajax
function storeMarker(){
var lng = document.getElementById("longitude").value;
var lat = document.getElementById("latitude").value;
//geeting the user data in form
var getVars = "?name=" + document.getElementById("name").value
+ "&address=" + document.getElementById("address").value
+ "&description=" + document.getElementById("description").value
+ "&property_type=" + document.getElementById("property_type").value
+ "&type=" + document.getElementById("type").value
+ "&lng="开发者_StackOverflow中文版 + lng
+ "&lat=" + lat ;
alert(getVars);//if i alert this its work mean all values i need from form is available
var request = GXmlHttp.create();
request.open('GET', 'storeMarker.php' + getVars, true);
}
now the problem is how can i access all variables in storeMarker.php through $_GET. I want each variables as a PHP var to do other things in php page. thanking you in anticipation
You simply do this;
if (isset($_GET['address'];){
$address = $_GET['address'];
}
if (isset($_GET['DESCRIPTIOM'];){
$description= $_GET['description'];
}
and so on for all the others. In php you access GET variables from the $_GET associative array and POST variables from $_POST
look here for some reference: http://php.net/manual/en/reserved.variables.get.php
Please try this way:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<script type='text/javascript'>
let number = 10;
document.write(number);
</script>
<?php
$number = '<script>document.write(number);</script>';
echo "<br>The number value is : ".$number;
?>
</body>
</html>
first of all print all parameters:
print_r($_GET);
You will see all passed parameters.
you can access parameters as:
$_GET['property_type']
or iterate through array:
foreach ($_GET as $k => $v) {
if ($k == 'property_type') {
//do something with value
}
}
精彩评论