jsonp的问题:请大家帮看看哪里错了“Uncaught SyntaxError: Unexpected token : ”
zouhc 2013-04-07 02:53:28 json真难搞,经常这里错哪里错,还找不到原因。今天调试下面的代码,通过jsonp获取其它服务器中的数据,谷歌总是提示下面的错误:
Resource interpreted as Script but transferred with MIME type text/json: "http://127.0.0.1:81/jsonp.php?callback=jQuery16206906629570294172_1365317138501&_=1365317138505". jquery-1.6.2.js:7752
Uncaught SyntaxError: Unexpected token : jsonp.php:1
IE浏览器提示:
行:2
Char:8
错误:缺少';'
代码:0
URL:http://localhost/ajax/jqueryajax.html
代码如下:
http://localhost/ajax/jqueryajax.html文件源码:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
</body>
<script type="text/javascript" src="js/jquery-1.6.2.js"></script>
<script type="text/javascript">
$(function(){
$.getJSON("http://127.0.0.1:81/jsonp.php?callback=?",function(data){
alert(data.name + data.age);
});
});
</script>
</body>
</html>
http://127.0.0.1:81/jsonp.php文件源码:
<?php
header("content-type:text/json;charset=utf-8");
header("Cache-Control: no-cache, must-revalidate");
$username='{"name":"老邹","age":1984}';
echo $username;
?>
我在我电脑里运行了两个php环境,两个程序分别放在不同的环境中,他们的端口号不一样。
请大家帮看看哪里错了,我就是找不到哪里错了。