<!--html 代码清单: [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.:9090/b.php", dataType: "jsonp", jsonp:"call", //jsonpCallback:"fn", //这行注释掉了,使用jQuery给出的默认方法 success:function(res){//res是json类型; alert(res.name); } }); }); //function fn(data){alert(data);} </script> </head> <body> </body> </html> **********服务端b.php 代码清单:********* *********[php] *********************************/ <?php header('Content-Type:text/html;Charset=utf-8'); $code = $_GET['code']; //传过来的数据 $call = $_GET['call']; //传过来的函数名,有可能是自定义,也有可能是jQery系统定义的。 $json_data='{"name":"li"}'; //正确的写法 // 正确的写法 $json_data='"zifuchang"'; 单引号里面是双引号,最里面是字符 //错误的写法 $json_data="zifuchang"; 正常的字符串写法,错误! $json_data='{"name":"li"}'; $res=$call. "(".$json_data.")"; echo $res; ?> |
|