test.php文件
<?php
$cb=$_GET['callback'];//getJSON('xxx.com?callback=?') 中的callback
$array=array('aaa'=>'aaa','bbb'=>'bbb');
$result=json_encode($array);
echo( $cb."(".$result.")");//加粗部分是要注意的
exit();
?>
test.html文件
<html><head>
<script type="text/javascript" src="http://djc84.blog.163.com/blog/./jquery.js"></script>
</head>
<body>
<script type="text/javascript">
$(function(){
$.getJSON("http://www.xxx.com/test.php?callback=?",function(data){
//var cc=data;
//$('#sss').html(cc);
alert(data.aaa);
});
});
</script>
</body>
</html>
<?php
$cb=$_GET['callback'];//getJSON('xxx.com?callback=?') 中的callback
$array=array('aaa'=>'aaa','bbb'=>'bbb');
$result=json_encode($array);
echo( $cb."(".$result.")");//加粗部分是要注意的
exit();
?>
test.html文件
<html><head>
<script type="text/javascript" src="http://djc84.blog.163.com/blog/./jquery.js"></script>
</head>
<body>
<script type="text/javascript">
$(function(){
$.getJSON("http://www.xxx.com/test.php?callback=?",function(data){
//var cc=data;
//$('#sss').html(cc);
alert(data.aaa);
});
});
</script>
</body>
</html>