0

Could you handle the name "John" in php from this getJson()? Could you assign it to a php variable?

var output = [];
$.getJSON('DisplayMap.php',{ Name: "john" },  function(data) {
           for (var i in data.b) {
            output.push(new google.maps.LatLng(data.b[i].Ya, data.b[i].Za));
        }

  });
JAAulde
  • 19,250
  • 5
  • 52
  • 63
Matt Jameson
  • 217
  • 1
  • 8
  • 21
  • 3
    Not without HTTP/ajax. PHP runs on the server; JavaScript (in this case) runs in the browser. – Matt Ball Jan 08 '13 at 20:18
  • are you asking how to send 'john' to php? because other than calling a php script on the server, php is irrelevant when it comes to json. json's just an encoding/transport format for data. – Marc B Jan 08 '13 at 20:21
  • possible duplicate of [decoding json value into a php variable](http://stackoverflow.com/questions/2307711/decoding-json-value-into-a-php-variable) – K-ballo Jan 08 '13 at 21:35
  • This is not a duplicate of the linked question. Further, for those confused by the question and who voted to close it, if you work with jQuery and PHP it's a pretty clear question (although the title is bit misleading and I will edit it). – JAAulde Jan 09 '13 at 01:04

2 Answers2

3

Since it will initiate a HTTP GET request, you can get variable in PHP as below

$Name = $_GET["name"];
Kemal Dağ
  • 2,743
  • 21
  • 27
1

This code will cause a GET request to ./DisplayMap.php with a query string variable named Name set to the value of john:

http://www.site.com/DisplayMap.php?Name=john

In PHP, you would access this via $_GET['Name'] or $_REQUEST['Name'].

As for the success function and what happens there, I don't really know what your system returns and it seems unrelated to your question.

JAAulde
  • 19,250
  • 5
  • 52
  • 63