test
test

Reputation: 18198

AJAX Get of JSON cancels

I'm trying to get the JSON file of a certain page on reddit and it cancels with no reason why..

Here's the URL i am trying to parse with JSON. http://reddit.com/r/VillagePorn/.json

UPDATED CODE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Sin título 1</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>    
    <script type="text/javascript">
$(document).ready(function () {    

                $.ajax({
    type: "GET",
    dataType: "json",
    url: "http://reddit.com/r/VillagePorn/.json?jsonp=?",
    success: function (data) {    
    $.each(data.data.children, function(i,item){
        $("<img/>").attr("src", item.data.url).appendTo("#res");
    });


    }
});
});​
</script>
</head>
<body>

<div id="res"></div>

</body>
</html>

Upvotes: 0

Views: 99

Answers (1)

Tarek
Tarek

Reputation: 3798

here is a working example : http://jsfiddle.net/fuRkG/

I think the issue is with the url , you need to add jsonp=? at the end

Answer based on this previous question : How to extract url data from Reddit API using JSON

Upvotes: 1

Related Questions