Specifying Different Response Types
The XmlHttpRequest
object—and therefore, the WinJS.xhr()
function—can be used to return several different types of data including blobs, documents, and text. You can use the responseType
option to specify how you want the data returned.
The default value of responseType
is text
. For example, the following request will return the contents of the XML feed as a string:
var options = { url: "http://stephenwalther.com/feed"};WinJS.xhr(options).done( function (xhr) { var result = xhr.response; // xhr.response is a string });
Most likely, you don’t want to return an XML document as a string because then you can’t use methods like querySelector()
and querySelectorAll() ...
Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.