HTML and CSS Reference
In-Depth Information
Getting remote data
You start by creating a new Windows 8 project using the Blank App template. Next, you create a
new Pages folder and add files such as header.html and footer.html from the previous chapters;
edit the default.html and default.css files accordingly. (This work is required only to ensure that all
applications have a consistent look and feel.) More importantly, open default.js and add the following
bootstrapping code:
app.onready = function (args) {
rssReaderApp.init();
};
The init function will be invoked when the application is fully loaded and ready to respond to the
user's commands. However, the init function doesn't exist yet. To create it, add a new JavaScript file
to the project under the Js folder and name it rssReaderApp.js . Here's the initial content for the new
file:
var rssReaderApp = rssReaderApp || {};
rssReaderApp.init = function () {
// To be done
}
At this point you should have a working—but empty—application. Let's spice it up a bit.
Getting familiar with XHr
In Windows 8, you use the WinJS.xhr object to perform access to remote HTTP endpoints. This object
gives you the ability to request an external URL and return whatever content the remote web server
provides. The WinJS.xhr object supports a variety of parameters, as you'll see in a moment; however,
most of the time you need only pass the plain HTTP address you want to reach to make it work.
Modify the rssReaderApp.init function, as shown below:
// This is the URL that provides RSS content
rssReaderApp.Feed = "http://news.google.com/news?pz=1&output=rss";
rssReaderApp.init = function () {
WinJS.xhr({ url: rssReaderApp.Feed }).then(function (rss) {
// Do something with the data
});
First, you save the URL you want to access as a public member of the rssReaderApp global object.
It is your responsibility to choose a URL that returns RSS data. If you are unfamiliar with RSS content,
you should recognize it on most websites from the popular icon shown in Figure 11-1.
Search WWH ::




Custom Search