js问题,跨域请求json
刚刚接触js,现在我用js实现这样的功能:
访问http://api.t.sina.com.cn/provinces.json 获得其中的json数据并打印出来,参考了一些资料。试着用jquery实现。代码如下
HTML code
<html>
<head>
<script language="javascript" type="text/javascript" src="js/jquery-1.7.1.min.js"> </script>
<script language="javascript" type="text/javascript" >
function getjs(){
url="http://api.t.sina.com.cn/provinces.json",
$.getJSON(url+"?jsoncallback=?",
function(data) {
document.write(data);
});
}
</script>
</head>
<body>
<input type="button" value="test" onClick="javascript:getjs();"/>
</body>
</html>
用firebug调试 ,请求了这个json的数据,但是有错误
HTML code
Resource interpreted as Other but transferred with MIME type undefined
Uncaught SyntaxError: Unexpected token
请问下大家,我是哪里出了问题呢? 谢谢
------解决方案--------------------
jsonp是要服务器提供支持的,从http://api.t.sina.com.cn/provinces.json这个地址返回的数据来看,并不支持jsonp跨域,因为他只是一个json文件,并不是一个回调函数的调用。