Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:53:10+00:00 2026-05-31T03:53:10+00:00

I have the following code grabbing a JSON object from github and I am

  • 0

I have the following code grabbing a JSON object from github and I am tring to add certain parts to an array.

function getTree(hash) {
    var pathToTree, returnedJSON;
    pathToTree = 'https://api.github.com/repos/myaccount/myrepo/git/trees/' + hash;
    $.ajax({
        accepts: 'application/vnd.github-blob.raw',
        dataType: 'jsonp',
        url: pathToTree,
        success: function (json) {
            returnedJSON = json;
        },
        error: function (error) {
            console.debug(error);
        }
    });
    return returnedJSON;
}

function parseTree(hash) {
    var objectedJSON, objectList = [], i, entry;
    objectedJSON = getTree(hash, function () {
        console.debug(objectedJSON);                    // this is not appearing in console
        for (i = 0;  i < objectedJSON.data.tree.length; i += 1) {
            entry = objectedJSON.data.tree[i];
            console.debug(entry);
            if (entry.type === 'blob') {
                if (entry.type.slice(-4) === '.svg') {     // we only want the svg images not the ignore file and README etc
                    objectList.append(i.content);
                }
            } else if (entry.type === 'tree') {
                    objectList.append(parseTree(getTree(entry.sha)));
            }
        }

    });
    return objectList;
}

$(document).ready(function () {
    var objects = parseTree('master', function () {
        console.debug(objects);
    });
});

I have the code retrieving the JSON object fine but I run into trouble when trying to get it parsed (aka pulling out the bits I want). The callbacks I am using do not seem to be going and was wondering if someone could look it over and help me out.

Specifically, can I add a callback to any function I choose? Do I have to do anything to that function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:53:12+00:00Added an answer on May 31, 2026 at 3:53 am

    I have fixed the code to illustrate how you would go about it.

    function getTree(hash, cb) {
        // notice that I copy the callback and hash references to have access to them in this 
        // function's closure and any subsequent closures, like the success and error
        // callbacks.
        var pathToTree, returnedJSON, cb = cb, hash = hash;
        pathToTree = 'https://api.github.com/repos/myaccount/myrepo/git/trees/' + hash;
        $.ajax({
            accepts: 'application/vnd.github-blob.raw',
            dataType: 'jsonp',
            url: pathToTree,
            success: function (json) {
                returnedJSON = json;
                // if anything was passed, call it.
                if (cb) cb(json);
            },
            error: function (error) {
                console.debug(error);
                // an error happened, check it out.
                throw error;
            }
        });
        return returnedJSON;
    }
    
    function parseTree(hash) {
        var objectedJSON, objectList = [], i, entry;
        objectedJSON = getTree(hash, function (objectedJSON) {
            console.debug(objectedJSON);                    // this is not appearing in console
            for (i = 0;  i < objectedJSON.data.tree.length; i += 1) {
                entry = objectedJSON.data.tree[i];
                console.debug(entry);
                if (entry.type === 'blob') {
                    if (entry.type.slice(-4) === '.svg') {     // we only want the svg images not the ignore file and README etc
                        objectList.append(i.content);
                    }
                } else if (entry.type === 'tree') {
                        objectList.append(parseTree(getTree(entry.sha)));
                }
            }
    
        });
        return objectList;
    }
    
    $(document).ready(function () {
        var objects = parseTree('master', function () {
            console.debug(objects);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function + code to parse and query a webservice request
I have following code which add BackButton on my view's navigation item's tabbar. It
I have following code import sys from ctypes import * from ctypes.util import find_library
I have following code: os.chdir(os.path.dirname(os.path.realpath(__file__)) + /../test) path.append(os.getcwd()) os.chdir(os.path.dirname(os.path.realpath(__file__))) Which should add /../test to
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I have following code class User attr_accessor :name end u = User.new u.name =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.