Question

I am trying to simply search the Discogs database and display the results in HTML, but when I try to perform the jQuery function getJSON it acts as if the URL I have provided is incorrect, as NOTHING will work inside the getJSON function. When I view the URL the function creates in a browser it does go to the correct JSON search page and brings up the correct results, but just won't let me parse through the results.

Could somebody tell me if there is a problem with the Discogs API URL I am trying to use, or if I am going wrong somewhere with my coding syntax?

Thanks in advance.

<!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>
Was it helpful?

Solution

I just needed to add a "callback=?" parameter and value to the JSON URL I was trying to access and it worked.

OTHER TIPS

Seems like a security issue. Probably trying to access from your local host and not a web server. When you put that URL into the browser, you get this message: {"message": "You must authenticate to access this resource."}

Also: I found this thread on Discogs forums. http://www.discogs.com/forum/thread/396480

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top