function btn1Click(mouseEvent) {
var msg = document.getElementById("msg");
WinJS.xhr({ url: "http://tuyano-sample.appspot.com/" }).done(……
function complete(result) {サーバーから受信したデータは、引数resultの「responseText」プロパティを指定して取り出すことができます。こうして取り出したテキストをtextContentに設定すれば完了です。
msg.textContent = result.responseText
msg.style.backgroundColor = "#336666";
}
function error(result) {エラーメッセージは、resultオブジェクトの「statusText」というもので取り出せます。後は、それを必要に応じて表示するだけですね。
msg.textContent = "ERROR!!: " + result.statusText;
msg.style.backgroundColor = "#FF0000";
});
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※default.htmlの<body>部分 <body id="body"> <h1 id="title">Sample Page</h1> <p id="msg" data-win-bind="style.color: color; style.background: bgcolor; style.fontSize: fsize">this is sample page.</p> <button id="button1">Click!</button> </body> ※default.js (function () { "use strict"; WinJS.Binding.optimizeBindingReferences = true; var app = WinJS.Application; var activation = Windows.ApplicationModel.Activation; app.onactivated = function (args) { if (args.detail.kind === activation.ActivationKind.launch) { if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {} else {} args.setPromise(WinJS.UI.processAll().then( function () { var btn1 = document.getElementById("button1"); btn1.addEventListener("click", btn1Click, false); } )); } }; app.oncheckpoint = function (args) {}; function btn1Click(mouseEvent) { var msg = document.getElementById("msg"); WinJS.xhr({ url: "http://tuyano-sample.appspot.com/" }) .done(function complete(result) { msg.textContent = result.responseText msg.style.backgroundColor = "#336666"; }, function error(result) { msg.textContent = "ERROR!!: " + result.statusText; msg.style.backgroundColor = "#FF0000"; }); } app.start(); })();
<< 前へ | 次へ >> |