mikehostetler / amplify

AmplifyJS
http://amplifyjs.com
GNU General Public License v2.0
1.45k stars 143 forks source link

AJAX request success callback returns nested object #34

Closed cocoahero closed 12 years ago

cocoahero commented 12 years ago

Hi,

I could be doing something ridiculously dumb, but I am trying to use amplify.request() to retrieve a user's github repos. Every example I read, the "data" parameter of the success callback is what it should be: the JSON deserialized into an object. However when I try and do this, the data parameter is actually an object with two properties, data.meta and data.data, with the data.data containing what I actually want.

Am I doing something wrong? Below is my source code.

$(function(){
    amplify.request.define("github-repos", "ajax", {
        url: "https://api.github.com/users/cocoahero/repos",
        dataType: "jsonp",
        type: "GET"
    });

    amplify.request("github-repos", function(data) {
        var html = "";
        $.each(data.data, function(i, repo) {
            html += "<h2>" + repo.name + "</h2>" + "<p>" + repo.description + "</p>";
        });
        $("#repos").html(html);
    });
});

Thanks!

scottgonzalez commented 12 years ago

That's how GitHub's API works. It returns meta data for JSONP calls.