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 9160873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:50:26+00:00 2026-06-17T13:50:26+00:00

I paste all of my code because it might have a connection with the

  • 0

I paste all of my code because it might have a connection with the function I am asking for. I had help to make one of my functions run. Look at the parseJSON() function. Why I have to use 2 functions (parseJSON() and nested makeNav(navigation)), but not only one parseJSON(navigation) (and ofc to change the inner elements from makeNav to parseJSON). Can someone explain why it works only that way for me. Because I want to understand it, not just to do my exercise and go on.

    var new_json;
    $.get('navigation.json', function (json){
        new_json = json;
        parseJSON();

        var reload_page;
        var this_hash = window.location.hash;

        if( this_hash.length == 0 ){
            reload_page = "home";
        }else{
            reload_page = this_hash.replace('#', '');
        };

        loading(reload_page + '.html');
    });

    var cache = {};

    function loading(url){


        if( typeof(cache[url]) == 'undefined' ) {
            console.log( 'cache A does not exists' );

            container.load(url + ' .container>*', function(){

                cache[url] = container.html();          
            });
        }else {
            console.log( 'cache A exists' );

            container.html(cache[url]);
        };
    };

    $('#navigation li a, #logo a').live('click',function(){

        var url = $(this).attr('href');

        window.location.hash = url.replace('.html', '');

        loading(url);

        return false;
    });




    function parseJSON() {

        function makeNav(navigation) {
            var nav_html = '';
            console.log( navigation.length );
            for (var i = 0; i < navigation.length; i++) {
                var name = navigation[i]['name'];
                var href = navigation[i]['href'];
                var submenu = navigation[i]['navigation'];

                nav_html += '<li><a href="' + href + '">' + name + '<span class="ddArrow"></span></a>';     

                if( typeof(submenu) != 'undefined' ){
                    nav_html += '<ul>';
                    nav_html += makeNav(submenu);
                    nav_html += '</ul>';
                }
                nav_html += '</li>';
            }
            return nav_html;
        }
        $('#navigation ul').html(makeNav( new_json['navigation'] ));
    }
  • 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-06-17T13:50:27+00:00Added an answer on June 17, 2026 at 1:50 pm

    Probable reason is that your parseJSON does extra things: $('#navigation ul').html(makeNav( new_json['navigation'])); and when you make recursive call to makeNav you don’t need to set this html content. Reason for the nested definition of makeNav inside parseJSON could be that you don’t want makeNav to be visible outside of the scope of parseJSON because you simply don’t use it out of this scope and you don’t want to pollute the “environment”.

    Anyway, I really don’t think that’s the best way to implement it…but that should be discussed at https://codereview.stackexchange.com/.

    To use a single function, without the nested makeNav you can do something like:

    var new_json;
    $.get('navigation.json', function (json){
        new_json = json;
        parseJSON();
    
        var reload_page;
        var this_hash = window.location.hash;
    
        if( this_hash.length == 0 ){
            reload_page = "home";
        }else{
            reload_page = this_hash.replace('#', '');
        };
        loading(reload_page + '.html');
    });
    
    var cache = {};
    
    function loading(url){
        if( typeof(cache[url]) == 'undefined' ) {
            console.log( 'cache A does not exists' );
            container.load(url + ' .container>*', function(){
                    cache[url] = container.html();          
            });
        }else {
            console.log( 'cache A exists' );
            container.html(cache[url]);
        };
    };
    
    $('#navigation li a, #logo a').live('click',function(){
        var url = $(this).attr('href');
        window.location.hash = url.replace('.html', '');
        loading(url);
        return false;
    });
    
    
    
    
    function makeNav(navigation) {
        var nav_html = '';
        console.log( navigation.length );
        for (var i = 0; i < navigation.length; i++) {
            var name = navigation[i]['name'];
            var href = navigation[i]['href'];
            var submenu = navigation[i]['navigation'];
    
            nav_html += '<li><a href="' + href + '">' + name + '<span class="ddArrow"></span></a>';     
    
            if( typeof(submenu) != 'undefined' ){
                nav_html += '<ul>';
                nav_html += makeNav(submenu);
                nav_html += '</ul>';
            }
            nav_html += '</li>';
        }
        return nav_html;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I copy a python code, and paste to vim. the indents are all
I have 6 list items $('.favorite-tag-group li').each(function(){ console.log(hi); }); This code however is displaying
If I copy all the files from the debug folder and paste it somewhere
Frequently I copy and paste code from my existing code base. Eclipse frequently brings
I have a following scenario: I have an ASP.NET MVC website/webapp where almost all
Description: I have many dropdowns on my page that all call a update price
I have a task, which I know how to code (in C#), but I
First of all, I have to thank StackOverflow and all its members for the
I have a database, with a few tables. One of them is a customer
I dont expect you to read the whole code. If you copy and paste

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.