1Passing data from PHP is easy, you can generate JavaScript with it. The other way is a bit harder - you have to invoke the PHP script by a Javascript request.
2
3An example (using traditional event registration model for simplicity):
4
5<!-- headers etc. omitted -->
6<script>
7function callPHP(params) {
8 var httpc = new XMLHttpRequest(); // simplified for clarity
9 var url = "get_data.php";
10 httpc.open("POST", url, true); // sending as POST
11
12 httpc.onreadystatechange = function() { //Call a function when the state changes.
13 if(httpc.readyState == 4 && httpc.status == 200) { // complete and no errors
14 alert(httpc.responseText); // some processing here, or whatever you want to do with the response
15 }
16 };
17 httpc.send(params);
18}
19</script>
20<a href="#" onclick="callPHP('lorem=ipsum&foo=bar')">call PHP script</a>
21<!-- rest of document omitted -->
22Whatever get_data.php produces, that will appear in httpc.responseText. Error handling, event registration and cross-browser XMLHttpRequest compatibility are left as simple exercises to the reader ;)
23
24See also Mozilla's documentation for further examples