您好,有没有办法使用WinJS在windows 8.1应用程序中使用Rest服务?

您好,有没有办法使用WinJS在windows 8.1应用程序中使用Rest服务?,rest,windows-8.1,winjs,Rest,Windows 8.1,Winjs,您好,我正在尝试使用windows 8.1应用程序中的REST服务,如果您能给我提供有关此主题的更多信息,我将不胜感激,谢谢 您可以使用该对象。但是,由于您使用的是WinsJS,因此该函数将更加方便 下面是一个关于如何使用它的示例: (function () { "use strict"; var app = WinJS.Application; app.onactivated = function (args) { // Change RSS fe

您好,我正在尝试使用windows 8.1应用程序中的REST服务,如果您能给我提供有关此主题的更多信息,我将不胜感激,谢谢

您可以使用该对象。但是,由于您使用的是WinsJS,因此该函数将更加方便

下面是一个关于如何使用它的示例:

(function () {
    "use strict";

    var app = WinJS.Application;

    app.onactivated = function (args) {

        // Change RSS feed URL as you need to.
        var resDiv = document.getElementById("divResult"),
            rssURL = "http://blogs.windows.com/windows/b/appbuilder/rss.aspx";

        // Call WinJS.xhr to retrieve an XML feed from the Web.
        WinJS.xhr({
            url: rssURL,
            responseType: "document"
        }).done(

            // When the result has completed, check the status.
            function completed(result) {
                if (result.status === 200) {

                    // Get the XML document from the results. 
                    var xmlDocument = result.responseXML,
                         title = xmlDocument.getElementsByTagName('title')[0];

                    // Update the HTML in the app.
                    resDiv.style.backgroundColor = "lightGreen";
                    resDiv.innerText = "Downloaded RSS feed from the " + title.textContent + " blog.";
                }
            });
    };

    app.start();
})();
实际上,自从8.1以来,微软一直在推广它,而不是“旧的”
WinJS.xhr
,因为,正如前面所说,它提高了它的(xhr)能力