在客户端和php服务器之间发送json数据

this is the server side code

<?php

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 01 Jan 2016 00:00:00 GMT');

header('Content-type: application/json');
$id = $_GET['id'];
$data = array("Hello", $id);
echo json_encode($data);

?>

and this is the client side code

<html>
<head>
<script src="jquery-1.1.1.min.js"></script>
<script language="javascript">
    function show(json) {
        alert(json);
    }
    function run() {
        $.getJSON("/localhost/jserver1.php",
            { id: 567 },
        show);
    }
    window.onload=run;
</script>
</head>
<body>
    JSON Test Page.
</body>
</html>

What i want to do here is i want to send messages between client and server using php and json. when i run the server side code i am getting the output as hello with the id given in the url in the localhost,but when i run the client side code i am getting only the body of the html page,I am not getting the alert with the input id that is there in the run method.Please someone tell me what is the problem

Instead of

    $.getJSON("URL",  
            { id: 567 },
           show 
            );
window.onload=run;

Use -

    $.getJSON("URL",  
            { id: 567 },
           function(response){
             show(response);
      });

window.onload=run();

Try with this code

function show(json) {
       alert(JSON.stringify(json));
}

Still very bad code, you should split up your files. But here we go:

<?php
if($_GET['id']) {
    $id = $_GET['id'];
    $data = array("Hello", $id);
    echo json_encode($data);
} else {

?>
<html>
<head>  
    <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script type="text/javascript">
    function show(json) {
       alert(json);
    }
    function run() {
       $.ajax({
            url : '/whatever/this/page/is',
            type : 'GET',
            data : 'id=567',
            success: function(res) {
                show(res);
            }
       });
    }


            window.onload=run;

        </script>

</head>

<body>

    JSON Test Page.

</body>
</html>
<? 
}

Try removing the / in front of /localhost/jserver1.php and adding http://.

Currently it refers to localhost/localhost/jserver1.php