HTML and CSS Reference
In-Depth Information
FIGURE 11-1 The popular icon that identifies links to URLs that return RSS data.
After you have determined the URL to invoke, you pass it along to the WinJS.xhr object. As usual
with operations that can be potentially lengthy, you need to write the code in asynchronous form.
WinJS.xhr({ url: rssReaderApp.Feed }).then( ... );
You pass an object to WinJS.xhr with the url property set to the URL to invoke. That's all that's
required; you don't need anything else for the call to take place. In the then method, place the code
that you want to run after a response has been obtained from the URL—in this case, after the RSS
data has been received. (The code in the then method will process the data and prepare it for display
in this case.)
A moment ago, you read that the URL is the only prerequisite for WinJS.xhr to be called.
Remember, though, that setting the URL correctly is no guarantee of success. A call may fail for a
number of reasons, and you must be able to detect failures. In addition, you should ensure that the
Windows 8 environment allows you to venture beyond the local machine and access the World Wide
Web. Finally, you should make sure that the request you are sending out is well formed for the server
that is going to receive it. Let's explore the options that you have to further configure the request.
Configuring the WinJS.xhr object
Table 11-1 enumerates the parameters you can optionally associate with a call to WinJS.xhr . These al-
low you to do things such as set the request type (for example, GET or POST ), specify user credentials
for remote authentication, set HTTP headers, and so forth.
TABLE 11-1 Options for calling the WinJS.xhr object
Parameter
Description
This is a required parameter that indicates the URL to invoke. The URL can be absolute or
relative. The HTTPS protocol is supported as well.
url
Indicates the HTTP method to be used to open the connection with the specified URL.
Valid values for this parameter are GET, POST, PUT, DELETE , or HEAD . The parameter is not
case-sensitive. If not specified, the type parameter defaults to GET .
type
You can use these parameters to specify credentials that are validated at the destination
before servicing the request. If the user parameter is empty or missing, and the site requires
authentication, then the user will be shown a logon window. If the user parameter is missing or
empty, the password parameter is ignored.
user password
 
Search WWH ::




Custom Search