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

  • Home
  • SEARCH
  • 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 8602485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:05:50+00:00 2026-06-12T02:05:50+00:00

So I was making a JavaScript AJAX loader for my blog and well it’s

  • 0

So I was making a JavaScript AJAX loader for my blog and well it’s not working. It was working before but when I attempted to add months into the parser and json file it just stopped and would not load.

Here is the JavaScript:

firstTime = 1;
function ajax_get_json_for_main_page(a){

var counter = 0;
var results = document.getElementById("blogShow");

    var hr = new XMLHttpRequest();
    hr.open("GET", "articles/main.json", true);
    hr.setRequestHeader("Content-type", "application/json", true);
    hr.onreadystatechange = function() {
        var blog = new Array()
        var title = "";

        if(hr.readyState == 4 && hr.status == 200) {
            var data = JSON.parse(hr.responseText);
            for(var obj in data){
                for(var entry in data[obj])
                {
                    blog[counter] = "<h4>"+entry[obj].title+"</h4><p>"+entry[obj].post+"</p>"+"<hr />";
                    title += "<a onClick='willImpletmentlater(" + entry[obj] + ")" + "'>" + entry[obj].title + "</a><br /><br />"
                    counter = counter + 1;
                }

            }
            document.getElementById("big3").innerHTML = title;

            if(firstTime == 1)
            {
            results.innerHTML = blog[0]
            firstTime = 1000;
            }


            if(a == 1)
            {
                interval = setInterval(function(){blogShowAnimateInner(1, blog);}, 1);
            }
            if(a == 2)
            {
                interval = setInterval(function(){blogShowAnimateInner(2, blog);}, 1);
            }
            if(a == 3)
            {
                interval = setInterval(function(){blogShowAnimateInner(3, blog);}, 1);
            }
            if(a == 4)
            {
                interval = setInterval(function(){blogShowAnimateInner(4, blog);}, 1);  
            }


        }
    }   


hr.send(null);




}

And also the JSON:

 {
     "june": {
        "17": {
            "title": "Monday 17 of June 2012",
            "post": "the post taken out to save space."
        },
        "16": {
            "title": "Sunday 16 of June 2012",
            "post": "the post taken out to save space"
        },
        "15": {
            "title": "Saturday 15 of June 2012",
            "post": "the post taken out to save space"
        },
        "14": {
            "title": "Friday 14 of June 2012",
            "post": "the post taken out to save space"
        },
        "13": {
            "title": "Thursday 13 of June 2012",
            "post": "the post taken out to save space"
        },
        "12": {
            "title": "Wednesday 12 of June 2012",
            "post": "the post taken out to save space"
        },
        "11": {
            "title": "Tuesday 11 of June 2012",
            "post": "the post taken out to save space"
        },
        "10": {
            "title": "Monday 10 of June 2012",
            "post": " the post taken out to save space."
        }
    }

}    

I tried to go on Jsfiddle but I don’t think they load ajax?
Either way they gave me no hints.

Edit:
I it’s working now here is the main parse bit as suggested.

if(hr.readyState == 4 && hr.status == 200) {
var data = JSON.parse(hr.responseText);

            var blog = [];
            var title = "";
            var counter = 0;

            for (var month in data) {
                var monthEntries = data[month];
                for (var i = 0; i < monthEntries.length; i++) {
                    var entry = monthEntries[i];
                    blog[counter] = "<h4>" + entry.title + "</h4><p>" + entry.post + "</p>" + "<hr />";
                    title += "<a onClick='willImpletmentlater(" + entry + ")" + "'>" + entry.title + "</a><br /><br />"
                    counter = counter + 1;
                }

            }

            console.log(blog);
            console.log(title);

            document.getElementById("big3").innerHTML = title;




            if(a == 1)
            {
                interval = setInterval(function(){blogShowAnimateInner(1, blog);}, 1);
            }
            if(a == 2)
            {
                interval = setInterval(function(){blogShowAnimateInner(2, blog);}, 1);
            }
            if(a == 3)
            {
                interval = setInterval(function(){blogShowAnimateInner(3, blog);}, 1);
            }
            if(a == 4)
            {
                interval = setInterval(function(){blogShowAnimateInner(4, blog);}, 1);  
            }


        }
    }   

Edit:
All good now

Edit:
It only works with june if I add july doesn’t work. Thats kinda wierd?

  • 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-12T02:05:52+00:00Added an answer on June 12, 2026 at 2:05 am

    Ah, I see what you mean. Your json response month object is not an array it is an object with key value pairs, and object keys have no set order of retrieval when you do var key…To get the expected order, you should change the json response to something like this

       {
         "june": [
            {
                "day": "17",
                "title": "Monday 17 of June 2012",
                "post": "the post taken out to save space."
            },
            {
                "day": "16", 
                "title": "Sunday 16 of June 2012",
                "post": "the post taken out to save space"
            },
            {
                "day": "15",
                "title": "Saturday 15 of June 2012",
                "post": "the post taken out to save space"
            },
            {
                "day":"14",
                "title": "Friday 14 of June 2012",
                "post": "the post taken out to save space"
            },
            {    "day": "13",
                "title": "Thursday 13 of June 2012",
                "post": "the post taken out to save space"
            },
            {    "day": "12",
                "title": "Wednesday 12 of June 2012",
                "post": "the post taken out to save space"
            }
        ]
    
    }
    

    I have updated the jsfiddle.

    http://jsfiddle.net/ew44p/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have my JavaScript making an Ajax call to /my_controller/ajax_action but then in
Well basically what the title says, when making an AJAX request with JavaScript. Does
I'm starting to give a little more attention to making my javascript and ajax
I am making a 2D game in javascript/ajax, that will be using data stored
I'm making a Javascript slideshow for my blog yet the array doesn't seem to
I'm following this tutorial about making an Ajax request on Rails: http://net.tutsplus.com/tutorials/javascript-ajax/using-unobtrusive-javascript-and-ajax-with-rails-3/ made _form
I have a javascript function making a AJAX get request and the callback setup
I have some javascript making an ajax call in my Rails site: $.ajax({type: PUT,
I have some JavaScript that is making an Ajax call to a relative url
I've rewritten my family web site using JavaScript (JQuery) making Ajax calls to PHP

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.