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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:40:04+00:00 2026-06-05T11:40:04+00:00

I am playing around with the Windows 8 Metro SDK atm but ran in

  • 0

I am playing around with the Windows 8 Metro SDK atm but ran in some trouble using WinJS.xhr.
If instead of returning the WinJS.xhr in the getData function i return some json object everything works fine, but i want to return an json object produced by a xhr request.

What is wrong in my attempt here? Thanks!! 🙂

(function () {
    "use strict";

function getData() {
    return WinJS.xhr({ url: "http://stackoverflow.com" }).done(
        function (request) {
            var results = [];
            var Item = {
                title: "title",
                text: "some text goes here"
            }
            results.push(Item);
            return results;
        },
        function (request) {
            var results = [];
            results.push({ title: "error", text: "error text" });
            return results;
        }
    );
}

var categoryList = new WinJS.Binding.List(getData());


var publicMembers = { itemList: categoryList };
WinJS.Namespace.define("Data", publicMembers);

})();
  • 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-05T11:40:06+00:00Added an answer on June 5, 2026 at 11:40 am

    You won’t be able to get your getData function to return the data itself – this is the nature of asynchronous operations in Javascript and Metro.

    The WinJS.xhr function returns a WinJS.Promise object, which represents an asynchronous operation. You should return this Promise to your caller, who can use the then or done methods to register callback functions that will be notified when the operation is complete (in the terminology of Promises, when the Promise is fulfilled).

    So, your caller of the getData function would look something like this:

    function myFunc() {
        getData().then(function(xhr) {
            // ...do something with the data when it arrives...
        }, function(err) {
            // ...do something with the error
        });
    }
    

    Notice that the callbacks are passed the XMLHttpRequest object.

    And your getData method becomes something like this:

    function getData() {
        return WinJS.xhr({ url: "http://stackoverflow.com" })
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Visual Studio 2012 and playing around with Windows Phone 7.1 application development.
I am currently playing around with encryption in the Windows Runtime. When using certain
I have been playing around with a simple application for Windows Phone 7 using
I was playing around with assembly, compiling to .com files using NASM on Windows
I've been playing around with the Windows api for uni, but I cant get
HI there, I'm playing around with the new Windows Phone 7 SDK and have
I accidentily was playing around with some code at school and then I ran
I am playing around some windows 8 stuff and wonder how I can do
For a few days now I have been playing around with the Windows Azure
I'm currently playing around with sideloading of Windows 8 applications in a corporate environment.

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.