2013-01-11 61 views
0

我試圖簡單地搜索Discogs數據庫並在HTML中顯示結果,但是當我嘗試執行jQuery函數getJSON時,它的行爲就好像我提供的URL不正確,因爲任何東西都不起作用在getJSON函數中。當我查看該函數在瀏覽器中創建的URL時,它會轉到正確的JSON搜索頁面並提供正確的結果,但不會讓我解析結果。Discogs API getJSON不起作用

有人可以告訴我是否存在Discogs API URL的問題我正在嘗試使用,還是因爲我的編碼語法在某處出錯?

在此先感謝。

<!DOCTYPE html> 
<html> 
<head> 
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
<title>Discogs Search</title> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$("#button").click(function(){ 
    $.getJSON("http://api.discogs.com/database/search?type=master&q=illmatic&page=1&per_page=100", function(data) { 
     $("#output").append("TEST"); 
     var theid = data.results[0].id;   
    }); 
}); 
}); 
</script> 
</head> 
<body> 
<button id="button">Search</button> 
<div id="output"></div> 
</body> 
</html> 

回答

1

我只需要添加一個「callback =?」參數和值的JSON網址我試圖訪問和它的工作。

0

看起來像一個安全問題。可能試圖從您的本地主機訪問而不是Web服務器。當您將該URL放入瀏覽器時,您會收到以下消息:{「message」:「您必須通過身份驗證才能訪問此資源。」}

此外:我在Discogs論壇上發現此線程。 http://www.discogs.com/forum/thread/396480