[英]How to get json response of third party domain using jsonp or jquery.getjson
我是这个Web编程的新手,我想在javascript中获取第三方域的json响应,因此我尝试使用Ajax http请求,但它仅适用于同一域。所以我尝试使用jsonp和jquery.getjson.Still我没有任何结果,请帮助我。
码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>get json in alert</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$.getJSON("http://cricketapi.mblogi.com/sfsjson.php?callback=?", function(result){
//response data are now in the result variable
alert(result);
});
</script>
</head>
<body>
</body>
</html>
您将需要确保所使用的URL以json格式返回数据。
例如,更新代码以访问Flickr提要:
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?ids=8623220@N02&format=json&jsoncallback=?", function(result){
//response data are now in the result variable
alert(result);
});
此处的键位于URL的末尾, &format=json&jsoncallback=?
告诉Flickr服务器发送回json数据。
因此,您的解决方案是更新URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.