Understanding WinJS.xhr
The xhr
function basically wraps the calls to XMLHttpRequest
in a Promise
object. The function is useful for cross-domain and intranet requests, as shown in the following code:
WinJS.xhr(options).then( function completed(result) { …. }, function error(result) { …. }, function progress(result) { …. },
Since the WinJS.xhr
function processes asynchronously and returns a Promise
object, we can pass the then()
or done()
method to it, as shown in the previous example.
You can use the WinJs.xhr
function to connect to a web service and to download different types of content, such as text or a JSON string that are specified in the responseType
option of WinJS.xhr
. The responseType
option takes a string value that specifies the type of response expected from the request, and the types are as follows:
text
: This is the default value and expects a response of type stringarraybuffer
: This expects an ArrayBuffer used to represent binary content such...