(1) test.php文件内容
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>test</title>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript">
function jsonpCallback(result)
{
//alert(result[1].name);
}
$(function(){
$.getJSON("http://localhost/jquery/json.php?callback=?", function(data)
{
$.each(data, function(index, comment){
//alert(comment.name);
return false;
});
});
$("div").each(function()
{
//alert($(this).text());
});
$("#loading").ajaxStart(function(){
$(this).show();
});
$("#loading").ajaxStop(function(){
$(this).hide();
});
});
</script>
<script type="text/javascript"src="http://localhost/jquery/json.php?callback=jsonpCallback"></script>
</head>
<body>
<div id="loading" style="display:none;">加载中...</div>
<div>wensummer</div>
<div>sunsummer</div>
</body>
(2)json.php文件内容
<?php
$callback = isset($_GET['callback'])?$_GET['callback']:'';
echo $callback."([ { name:'John',age:'19'},{ name:'joe',age:'20'}] );";
echo $callback;
?>