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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:45:14+00:00 2026-06-16T22:45:14+00:00

I’m working on my 1st WinJS app for Windows 8 and I’m just trying

  • 0

I’m working on my 1st WinJS app for Windows 8 and I’m just trying to replace the base code given in 2 grid template and I’m getting this error:

Unable to get property 'forEach' of undefined or null reference

My code:

getData().forEach(function (item) {
    list.push(item);
});

The initial function:

function getData() {

    // JSON request
    WinJS.xhr({
        type: "GET",
        url: "http://mytld.com/mobile/pagethatreturnsjsondata.php"
    }).then(
            function (response) {
                OnSuccessCall(response);
            },
            function (error) {
                var err = error;
                console.log("Error : " + err.message);
            },
            function (progress) { }
    );
}

The following is getting the data from a php webservice which is returning JSON data:

function OnSuccessCall(response) {
    var itemContent = "<p>Item Content</p>";
    var itemDescription = "Item Description";
    var groupDescription = "Group Description";

    // These three strings encode placeholder images. You will want to set the
    // backgroundImage property in your real data to be URLs to images.
    var darkGray = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXY3B0cPoPAANMAcOba1BlAAAAAElFTkSuQmCC";
    var lightGray = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXY7h4+cp/AAhpA3h+ANDKAAAAAElFTkSuQmCC";
    var mediumGray = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXY5g8dcZ/AAY/AsAlWFQ+AAAAAElFTkSuQmCC";

    // Each of these sample groups must have a unique key to be displayed separately.
    var sampleGroups = [
        { key: "group1", title: "prayers", subtitle: "submitted prayers", backgroundImage: darkGray, description: groupDescription }
    ];

    var x = response.responseText.length;
    var json = JSON.parse(response.responseText);
    var sampleItems = [];
    for (var i = 0; i < json.length - 1; i++) {
        sampleItems.push({
            group: sampleGroups[0],
            title: json[i].text,
            subtitle: "Item Subtitle: 1",
            description: itemDescription,
            content: itemContent,
            backgroundImage: lightGray
        });
    }

    return sampleItems;
}

I’m able to see data in sampleItems:

watch window with object data

I’m obviously doing something wrong, as when I compare my object results with the results from the original example data they are virtually the same.

Any help is appreciated.

  • 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-16T22:45:15+00:00Added an answer on June 16, 2026 at 10:45 pm

    Your getData() function does not have a return statement, so it returns undefined. And you cannot forEach on undefined.

    Looking at the bigger picture: Your getData() uses xhr, so it does not actually return the results, Instead, it gets the data asynchronously. You therefore cannot forEach the return value because the results don’t exist yet. You have to wait for the promise to complete, and then you can call forEach on the promise result.

    function getData() {
        // add "return" here so the function returns a Promise
        return WinJS.xhr({
            type: "GET",
            url: "http://mytld.com/mobile/pagethatreturnsjsondata.php"
        }).then(
                function (response) {
                    // add "return" here to specify the promise's completed value
                    return OnSuccessCall(response);
                },
                function (error) {
                    var err = error;
                    console.log("Error : " + err.message);
                },
                function (progress) { }
        );
    }
    

    Now that getData() returns something (a Promise) you can schedule work to occur when the promise completes.

    getData().then(function(results) { results.forEach(...) });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.