|
<?php
$arr=array('name'=>"sanzhixiong",'age'=>'22');
echo json_encode($arr);
?>
这是php代码
下面是jquery的代码
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function(){
$("#load").click(function(){
$.post(
'http://localhost/json.php',
function(data)
{
alert(data.name);
});
});
});
</script>
</head>
<body>
<input type='button' value='load' id='load'>
<div id="json"></div> |
|