簡體   English   中英

如何使用jsonp或jquery.getjson獲取第三方域的json響應

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM