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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:54:24+00:00 2026-05-23T07:54:24+00:00

Here I have a very strange issue in my code. I’ve tried to ask

  • 0

Here I have a very strange issue in my code. I’ve tried to ask out of here but nobody seems to find the logic to this problem.

I’ll paste my code:

$(document).ready(function(){
        var max = 5;
        var d = new Date();
        var today = $.format.date(d, 'yyyy-MM-ddTHH:mm:ss');
        d.setDate(d.getDate() - 1);
        var yesterday = $.format.date(d, 'yyyy-MM-ddTHH:mm:ss');
        var querys = {
            'upcoming' : 'https://www.google.com/calendar/feeds/user/private-magic-cookie/full?alt=jsonc&v=2&start-index=1&max-results='+ max +'&orderby=starttime&sortorder=ascending&start-min=' + today ,
            'previous': 'https://www.google.com/calendar/feeds/user/private-magic-cookie/full?alt=jsonc&v=2&start-index=1&max-results='+ max +'&orderby=starttime&sortorder=descending&start-max=' + yesterday
        };
        var items = [];             
        $.each(querys, function(key, val) {
            items[key] = [];
            var typeOfEvent = key;
            $.getJSON(val, function(data) {             
                $.each(data.data.items, function(key, val) {                    
                    var when = $.format.date(val.when[0].start, 'dd-MM-yyyy HH:mm');        
                    if (when.search('/:/') == -1) //If no hours where indicated at the event
                        when = when.replace(/(\d{4})-(\d\d)-(\d\d)/, '$3-$2-$1');
                    items[typeOfEvent].push('<li id="' + key + '">' + val.title + ': El ' + when + '</li>');            
                });
            });
        });
        console.log(items); 
        $.each(items, function(key, val){
        var append = $('<ul/>').text(val.join(''));
        $(append).appendTo('body');
    });

    });

So, the last portion, the one supposed to append the array as a list to the body doesn’t do nothing. No errors, no execution of code there. The console.log you see before, outputs the array perfectly at the console…

So, what’s the matter here?

  • 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-23T07:54:25+00:00Added an answer on May 23, 2026 at 7:54 am

    I see two problems with that loop:

    • You are using the .each method instead of the $.each method, so you are using the items array as if it was an array of DOM elements.

    • You are creating a string, but then you are using it as a jQuery object. There is no appendTo method in the String object.

    You can use jQuery to create the element instead of creating HTML code to be parsed:

    $.each(items, function (key, val){
      var append = $('<ul/>').html(val.join(''));
      append.appendTo('body');
    });
    

    Edit:

    As the data is fetched with AJAX, the array will be empty when this code runs. You would have to put the code inside the callback instead, and make sure that it only runs for the last callback:

    $(document).ready(function(){
      var max = 5, d = new Date();
      var today = $.format.date(d, 'yyyy-MM-ddTHH:mm:ss');
      d.setDate(d.getDate() - 1);
      var yesterday = $.format.date(d, 'yyyy-MM-ddTHH:mm:ss');
      var querys = {
        'upcoming' : 'https://www.google.com/calendar/feeds/user/private-magic-cookie/full?alt=jsonc&v=2&start-index=1&max-results='+ max +'&orderby=starttime&sortorder=ascending&start-min=' + today ,
        'previous': 'https://www.google.com/calendar/feeds/user/private-magic-cookie/full?alt=jsonc&v=2&start-index=1&max-results='+ max +'&orderby=starttime&sortorder=descending&start-max=' + yesterday
      };
      var items = {}, cnt = 0;
      $.each(querys, function(key, val) {
        items[key] = [];
        var typeOfEvent = key;
        cnt++; // count the requests
        $.getJSON(val, function(data) {             
          $.each(data.data.items, function(key, val) {                    
            var when = $.format.date(val.when[0].start, 'dd-MM-yyyy HH:mm');        
            if (when.search('/:/') == -1) //If no hours where indicated at the event
              when = when.replace(/(\d{4})-(\d\d)-(\d\d)/, '$3-$2-$1');
            items[typeOfEvent].push('<li id="' + key + '">' + val.title + ': El ' + when + '</li>');            
          });
          if (--cnt == 0) { // check for last request
            console.log(items); 
            $.each(items, function(key, val){
              $('<ul/>').html(val.join('')).appendTo('body');
            });
          }
        });
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a strange issue. I have a very simple piece of code
This code compiles but looks very strange. I have a typical and simple parent/child
I have very strange issue, on most browsers (ie, ff, chrome, safari). Here is
I have a very strange issue going on here. It's only occurring on Internet
I have a very strange issue, that I'm hoping someone here can help me
I have a very strange behavior with Request.Form . Here are two IIS 7
This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
I have an XML file that is very long, but here is a shot
I have a very strange situation happening and I'm hoping someone here knows why.
I have very strange issue. In my WP7 app I have a pivot control

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.