<!--html 代碼清單:
*/
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="jquery-1.7.min.js"></script>
<script type="text/javascript">
$(function(){
$.ajax({data:{"code":200},
type: "get",
url:"http://ttzz.meibu.net:9090/b.php",
dataType: "jsonp",
jsonp:"call",
//jsonpCallback:"fn", //這行注釋掉了,使用jQuery給出的默認(rèn)方法
success:function(res){//res是json類型;
alert(res.name);
}
});
});
//function fn(data){alert(data);}
</script>
</head>
<body>
</body>
</html>
**********服務(wù)端b.php 代碼清單:*********
*********[php] *********************************/
<?php
header('Content-Type:text/html;Charset=utf-8');
$code = $_GET['code']; //傳過(guò)來(lái)的數(shù)據(jù)
$call = $_GET['call']; //傳過(guò)來(lái)的函數(shù)名,有可能是自定義,也有可能是jQery系統(tǒng)定義的。
$json_data='{"name":"li"}'; //正確的寫法
// 正確的寫法 $json_data='"zifuchang"'; 單引號(hào)里面是雙引號(hào),最里面是字符
//錯(cuò)誤的寫法 $json_data="zifuchang"; 正常的字符串寫法,錯(cuò)誤!
$json_data='{"name":"li"}';
$res=$call. "(".$json_data.")";
echo $res;
?>