0

我正在创建访问 Web 服务并在 html 页面上显示数据的 win 8 应用程序。

PAGE1.html 从 Web 服务访问数据。第一次打开 PAGE1 时,从 Web 服务正确检索数据,然后我从 PAGE1 上调用window.location("PAGE2.html. 但是当我导航回 PAGE1.html 时,这个 PAGE1.html 打开但不显示更新的数据。

PAGE1.html 的 PAGE1.js 代码:在页面的 onload 功能上正确地从 Web 服务获取数据。

ready: function (element, options) 
{
    var textDisp= document.querySelector("#text");   //text is DIV id to display data

    textDisp.innerText = "PAGE2";
    document.querySelector("#myButton").onclick = function (args) {
            WinJS.Navigation.navigate("/pages/page2/page2.html");
        };
    WinJS.xhr({
       type: "GET",
        url: "http://MyWebserice",
    headers: { "Content-type": "application/json" },
    }).then(function complete(request) {
                 var resdata = request.responseText;
                 textDisp.innerText = resdata;
             }, function error(er) {
                 var err = er.statusText;
             });
     }

数据通过网络服务正确提交到数据库;这里是 PAGE2.html 的 PAGE2.js 的代码:

document.querySelector("#Submit").onclick = function (args) {
       WinJS.xhr({
               type: "POST",
               url: "http://InsertData?username=" + un + "&password=" + pass + "",
               headers: { "Content-type": "application/json" },
            }).then(function complete(request) {
                        WinJS.Navigation.navigate("/pages/PAGE1/PAGE1.html");
                    }, function error(er) {
                        var err = er.statusText;
            });
}

但是添加数据成功后,PAGE1没有显示数据库的刷新数据,我 WinJS.Navigation.navigate("/pages/PAGE1/PAGE1.html")在WinJS.xhr中调用然后转到PAGE1.html。

4

0 回答 0