客户端:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<script language="javascript" src="jquery-2.0.2.min.js" mce_src="jquery-1.4.js"></script>
<script type="text/javascript">
$(document).ready(function (){
$('#latest').click(function (){
$.getJSON("http://localhost/cc/server.php?&callback=?",
function(data){ // 往后台传递的参数
// data = JSON.parse(data);
alert(data.userID);alert(data.groupID);
})
})
});
</script>
</head>
<body>
</body>
<button id="latest">点击获取</button>
</html>
服务器端:
<?php
$json ='{userID:123,groupID:4}';
echo $_GET['callback']."(".$json.")";
?>
本文介绍了一个简单的示例,展示了如何使用jQuery发起AJAX请求并从服务器端获取JSON格式的数据。通过点击按钮触发事件,客户端能够调用服务器端脚本(server.php)并接收返回的JSON数据。
1047

被折叠的 条评论
为什么被折叠?



